Extracting specific numbers

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
zirjeo
Posts: 82
Joined: Fri Oct 28, 2016 1:49 am

Extracting specific numbers

Post by zirjeo » Fri Oct 28, 2016 2:04 am

If I have a Parcel number of 123-456-78 if I wanted to extract only the first 3 characters I believe I would do this...

Code: Select all

TAG POS=23 TYPE=TD ATTR=* EXTRACT=TXT
SET !VAR1 EVAL("var x=\"{{!EXTRACT}}\"; x=x.match(/^.{3}/).join(''); x;")
PROMPT {{!VAR1}
But say I wanted to extract the middle 3 characters how would I go about doing this? I'm looking for it in a way in which it extracts characters 4 through 6 and disregards the dashes, instead of ignoring specific numbers or taking what's between the dashes because the parcel number will always be changing and there may or may not be dashes.
Thank you
chivracq
Posts: 9004
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Extracting specific numbers

Post by chivracq » Fri Oct 28, 2016 9:56 am

zirjeo wrote:If I have a Parcel number of 123-456-78 if I wanted to extract only the first 3 characters I believe I would do this...

Code: Select all

TAG POS=23 TYPE=TD ATTR=* EXTRACT=TXT
SET !VAR1 EVAL("var x=\"{{!EXTRACT}}\"; x=x.match(/^.{3}/).join(''); x;")
PROMPT {{!VAR1}
But say I wanted to extract the middle 3 characters how would I go about doing this? I'm looking for it in a way in which it extracts characters 4 through 6 and disregards the dashes, instead of ignoring specific numbers or taking what's between the dashes because the parcel number will always be changing and there may or may not be dashes.
Thank you
CIM...! :mrgreen:
Start using the Forum correctly from the beginning by always mentioning your FCI when you open a Thread or if you post for the first time in some existing Thread (read my Sig), many Commands are not implemented for all Browsers/Versions, even if it won't really matter for this one... But I only answer Threads where Users mention their FCI...

Hum, your complex 'match()' + 'join()' Statement maybe does "the job" to extract the first 3 Digits, easier was using 'split()' (if Dashes) or 'subStr()' or 'subString()'... And those would be the Commands to use to extract the 3 middle Digits, combined with a Check on 'length' and/or 'indexOf()', but there are several Solutions to achieve what you want...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
zirjeo
Posts: 82
Joined: Fri Oct 28, 2016 1:49 am

Re: Extracting specific numbers

Post by zirjeo » Fri Oct 28, 2016 3:04 pm

Windows 10, IE 11, VERSION BUILD=11.5.498.2403

For the below what code would split at 3rd character or number in and also character 7? Im guessing it would be something like Index 2 and 6. Please see my first post for further detail on what I'm trying to accomplish.

Code: Select all

SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var x,y,z; y=s.split(what code here would represent 3 character or number in); z=y[1].split(and character 7); z[0];")
Also is there anything I can add to make it disregard dashes?

Thank you
chivracq
Posts: 9004
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Extracting specific numbers

Post by chivracq » Fri Oct 28, 2016 6:40 pm

zirjeo wrote:

Code: Select all

Windows 10, 
IE 11, 
VERSION BUILD=11.5.498.2403
For the below what code would split at 3rd character or number in and also character 7? Im guessing it would be something like Index 2 and 6. Please see my first post for further detail on what I'm trying to accomplish.

Code: Select all

SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var x,y,z; y=s.split(what code here would represent 3 character or number in); z=y[1].split(and character 7); z[0];")
Also is there anything I can add to make it disregard dashes?

Thank you
OK, FCI mentioned, perfect...! :D

Well, if you always had the 2 Dashes, using 'split()' would indeed be the most straightforward Solution.
Oh...!, and you found one of my Examples, I see...! Very good...! Then, using this Example, you simply do twice the 'split()' on the Dash Character (even if once is enough, 'y[1]' already contains the Data you want to keep):

Code: Select all

SET !EXTRACT "123-456-78"
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var x,y,z; y=s.split('-'); z=y[1].split('-'); z[0];")
But because in your case, you do twice a 'split()' on the same (Dash) Character, that can be simplified to:

Code: Select all

SET !EXTRACT "123-456-78"
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var x,y,z; y=s.split('-'); y[1];")
But 'split()' won't be really useful if you sometimes don't get the Dashes included in your Extract..., hum, except if the "123" or "789" part(s) remain(s) constant...

But, I'm a bit busy right now, preparing some DJ-Sets for tonight and tomorrow, WE's are always a bit hectic for me, ah-ah..., check how 'replace()' + indexOf()' + 'subStr()' + 'subString()' work and you should be able to find a Solution by yourself, your original Post with 'match()' + 'join()' was much more complex already...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
zirjeo
Posts: 82
Joined: Fri Oct 28, 2016 1:49 am

Re: Extracting specific numbers

Post by zirjeo » Wed Nov 09, 2016 4:53 am

chiv! I get it. I'm loving this substring method, it's so simple to use. I can rearrange numbers, remove dashes or even add dashes with this. Thanks! :mrgreen:

Code: Select all

SET !VAR1 EVAL("var parc = \"{{!EXTRACT}}\"; var a = parc.substring(0,3); var a;")
chivracq
Posts: 9004
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Extracting specific numbers

Post by chivracq » Wed Nov 09, 2016 10:02 pm

zirjeo wrote:chiv! I get it. I'm loving this substring method, it's so simple to use. I can rearrange numbers, remove dashes or even add dashes with this. Thanks! :mrgreen:

Code: Select all

SET !VAR1 EVAL("var parc = \"{{!EXTRACT}}\"; var a = parc.substring(0,3); var a;")
Good...!, finally...!! Ah-ah...! :D

Yep, 'subString()' is easy to use and powerful, and everything you can do with 'subString()', you can do it as well with 'subStr()' which can be very useful as well, especially if the Length of your String may vary...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
Post Reply