Multiple dashes, extracting last 3 numbers.

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.

Moderators: Community Moderators, iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

Multiple dashes, extracting last 3 numbers.

by zirjeo on Mon Nov 07, 2016 9:30 pm

Windows 10, IE 11, VERSION BUILD=11.5.498.2403

Extracted the text....

2637-027-017

I'm trying to isolate the last 3 numbers after the 2nd dash strictly using the dashes because the numbers will always change. I tried the below but I keep getting 027 instead of 017

Code: Select all
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var x,y; y=s.split('-'); z=y[1].split('-'); z[1];")


Even if I just try
Code: Select all
SET !VAR2 EVAL("var s='{{!EXTRACT}}'; var x,y; y=s.split('-'); y[1];")


It still only picks up 027, would think it would pick up 027-017. It must not like the duplicate dashes. Any ideas?
WIndows 10, IE11, VERSION BUILD=11.5.498.2403
zirjeo
 
Posts: 42
Joined: Thu Oct 27, 2016 6:49 pm

Re: Multiple dashes, extracting last 3 numbers.

by chivracq on Tue Nov 08, 2016 6:55 am

zirjeo wrote:
Code: Select all
Windows 10,
IE 11,
VERSION BUILD=11.5.498.2403


Extracted the text....

2637-027-017

I'm trying to isolate the last 3 numbers after the 2nd dash strictly using the dashes because the numbers will always change. I tried the below but I keep getting 027 instead of 017

Code: Select all
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var x,y; y=s.split('-'); z=y[1].split('-'); z[1];")


Even if I just try
Code: Select all
SET !VAR2 EVAL("var s='{{!EXTRACT}}'; var x,y; y=s.split('-'); y[1];")


It still only picks up 027, would think it would pick up 027-017. It must not like the duplicate dashes. Any ideas?

Yep normal, y[0] returns the first part of the 'split()' (=> "2637"), y[1] returns the second part (=> "027") and y[2] returns the third part (=> "017").
=> What you want is simply:
Code: Select all
SET !VAR2 EVAL("var s='{{!EXTRACT}}'; var x,y; y=s.split('-'); y[2];")

Other Solution would be to use 'subStr('-3')', like I had mentioned in some previous Thread of yours where you didn't follow up anymore / which you didn't finish neatly btw...! :shock:
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 5322
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Multiple dashes, extracting last 3 numbers.

by zirjeo on Tue Nov 08, 2016 9:01 am

Thanks that works even though it doesn't quite make sense to me, I don't see how there can be a 3rd part of a split seeing split means to split something in 2. But it works.

The old post I didn't respond on because I had no solution. No idea how to split out 123 out of 12345678.
WIndows 10, IE11, VERSION BUILD=11.5.498.2403
zirjeo
 
Posts: 42
Joined: Thu Oct 27, 2016 6:49 pm

Re: Multiple dashes, extracting last 3 numbers.

by chivracq on Tue Nov 08, 2016 10:08 am

zirjeo wrote:Thanks that works even though it doesn't quite make sense to me, I don't see how there can be a 3rd part of a split seeing split means to split something in 2. But it works.

Well, you have 2 Dashes in your String, then splitting your String on the Dash produces 3 parts.
If you had 3 Dashes, splitting your String on the Dash would produce 4 parts... Etc...

zirjeo wrote:The old post I didn't respond on because I had no solution. No idea how to split out 123 out of 12345678.

Hum, then you should have followed up anyway and mentioned it, I normally stop helping Users if they don't "use the Forum a bit correctly", and following up on all their Threads (and finishing them "neatly" and useful as well for other Users searching the Forum with a similar Qt/Case) is one of my "Criteria"... :idea:

But you would find the Solution (well, "a" Solution, because there are at least half a dozen ways to do what you want...) very easily if you read a bit the Documentation on all the JavaScript Functions I mentioned in that other Thread, it's really very basic Level with thousands of Examples on Internet and even our Forum..., and again, 'subStr()' would do the job directly like in this current Thread...

The only a little bit confusing thing that I find myself with all those JavaScript Functions for String Manipulation, or at least not very-very logical, is that the Index for all Chars in a String always starts at 0, Char_at_Index=0 = 1st Char, Char_at_Index=1 = 2nd Char, etc..., same thing for Arrays like for 'split()'. And I'm not completely sure about the "always", I think I remember there are a few Exceptions...! :?
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 5322
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Multiple dashes, extracting last 3 numbers.

by zirjeo on Tue Nov 08, 2016 11:28 am

Ok I will look into it, when/if I figure it out ill respond to other post. Thanks
WIndows 10, IE11, VERSION BUILD=11.5.498.2403
zirjeo
 
Posts: 42
Joined: Thu Oct 27, 2016 6:49 pm


Return to Data Extraction and Web Screen Scraping

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Website Monitoring