Extracting specific 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.

Extracting specific numbers

by zirjeo on Thu Oct 27, 2016 7:04 pm

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
WIndows 10, IE11, VERSION BUILD=11.5.498.2403
zirjeo
 
Posts: 59
Joined: Thu Oct 27, 2016 6:49 pm

Re: Extracting specific numbers

by chivracq on Fri Oct 28, 2016 2: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)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 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: 6489
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Extracting specific numbers

by zirjeo on Fri Oct 28, 2016 8:04 am

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
WIndows 10, IE11, VERSION BUILD=11.5.498.2403
zirjeo
 
Posts: 59
Joined: Thu Oct 27, 2016 6:49 pm

Re: Extracting specific numbers

by chivracq on Fri Oct 28, 2016 11:40 am

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)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 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: 6489
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Extracting specific numbers

by zirjeo on Tue Nov 08, 2016 9:53 pm

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;")
WIndows 10, IE11, VERSION BUILD=11.5.498.2403
zirjeo
 
Posts: 59
Joined: Thu Oct 27, 2016 6:49 pm

Re: Extracting specific numbers

by chivracq on Wed Nov 09, 2016 3: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)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 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: 6489
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)


Return to Data Extraction and Web Screen Scraping

Who is online

Users browsing this forum: No registered users and 1 guest

-->