Extract Data Using csv. & String Fn. Open Multi Tab

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.

Extract Data Using csv. & String Fn. Open Multi Tab

by Tamilselvan on Fri Jan 27, 2017 4:37 am

Version 9.0.3
Windows 10
Firefox 50.1.0

Sir,
I extract data from csv. file. contain few digits.

csv.file :
/87-
/90-
/482-
/77-
/85-
/279-
/489-
/285-

Using It extracted from drop down list and compare the both csv.file & extracted.
In drop down list different from extracted text (i.e. index value extracted )
Drop Down List.jpg

So i could not use #EANF# method.

Some time extracted text vary. (i.e. index value length)
EXTRACTED DATA.jpg
EXTRACTED DATA.jpg (12.5 KIB) Viewed 193 times

so depends upon csv file length. compare extracted text. In mean time I am using String function. I get following error.

"VAR4 is not defined, line: 26 (Error code: -1001)"

Kindly do the needful.
Here is the code :

VERSION BUILD=9030808 RECORDER=FX
TAB T=1
SET !DATASOURCE "C:\\Users\\OFFICE\\Documents\\iMacros\\Datasources\\JobCard-No.csv"
SET !LOOP 2
SET !DATASOURCE_LINE {{!LOOP}}

'Select Beneficiary Job Card No.
TAG POS=1 TYPE=SELECT FORM=ID:aspnetForm ATTR=ID:ctl00_ContentPlaceHolder1_DDL_Registration CONTENT=%*{{!COL1}}*
WAIT SECONDS=1

SET !EXTRACT NULL
'Extract your Element:
TAG POS=1 TYPE=SELECT ATTR=NAME:ctl00$ContentPlaceHolder1$DDL_Registration EXTRACT=TXT
SET !VAR1 EVAL("var s=\"{{!COL1}}\"; s.length")
PROMPT {{!EXTRACT}}
SET !VAR3 18
SET !VAR4 !VAR3 s.toString()
SET !VAR5 !VAR1.toString()
SET !Sub_Str1 EVAL("var s=\"{{!EXTRACT}}\"; s.substr(VAR4,VAR5)")
PROMPT {{!Sub_Str1}}
'Spit out a "1" or "2" to reuse for "TAB T=n":
SET TAB_Nb EVAL("var s='{{Sub_Str1}}'; var z; if(s=='{{!COL1}}'){z=1;} else{z=2;}; z;")
'Stay on TAB_1 if Element found or switch to TAB_2 if not found:
TAB OPEN
TAB T={{TAB_Nb}}
Tamilselvan
 
Posts: 36
Joined: Mon Mar 07, 2016 3:49 am

Re: Extract Data Using csv. & String Fn. Open Multi Tab

by chivracq on Fri Jan 27, 2017 7:33 am

Tamilselvan wrote:
Code: Select all
Version 9.0.3
Windows 10
Firefox 50.1.0


Sir,
I extract data from csv. file. contain few digits.

csv.file :
Code: Select all
/87-
/90-
/482-
/77-
/85-
/279-
/489-
/285-


Using It extracted from drop down list and compare the both csv.file & extracted.
In drop down list different from extracted text (i.e. index value extracted )
Drop Down List.jpg

So i could not use #EANF# method.

Some time extracted text vary. (i.e. index value length)
EXTRACTED DATA.jpg

so depends upon csv file length. compare extracted text. In mean time I am using String function. I get following error.
Code: Select all
"VAR4 is not defined, line: 26 (Error code: -1001)"


Kindly do the needful.
Here is the code :
Code: Select all
VERSION BUILD=9030808 RECORDER=FX
TAB T=1
SET !DATASOURCE "C:\\Users\\OFFICE\\Documents\\iMacros\\Datasources\\JobCard-No.csv"
SET !LOOP 2
SET !DATASOURCE_LINE {{!LOOP}}

'Select Beneficiary Job Card No.
TAG POS=1 TYPE=SELECT FORM=ID:aspnetForm ATTR=ID:ctl00_ContentPlaceHolder1_DDL_Registration CONTENT=%*{{!COL1}}*
WAIT SECONDS=1

SET !EXTRACT NULL
'Extract your Element:
TAG POS=1 TYPE=SELECT ATTR=NAME:ctl00$ContentPlaceHolder1$DDL_Registration EXTRACT=TXT
SET !VAR1 EVAL("var s=\"{{!COL1}}\"; s.length")
PROMPT {{!EXTRACT}}
SET !VAR3 18
SET !VAR4 !VAR3 s.toString()
SET !VAR5 !VAR1.toString()
SET !Sub_Str1 EVAL("var s=\"{{!EXTRACT}}\"; s.substr(VAR4,VAR5)")
PROMPT {{!Sub_Str1}}
 'Spit out a "1" or "2" to reuse for "TAB T=n":
SET TAB_Nb EVAL("var s='{{Sub_Str1}}'; var z; if(s=='{{!COL1}}'){z=1;} else{z=2;}; z;")
'Stay on TAB_1 if Element found or switch to TAB_2 if not found:
TAB OPEN
TAB T={{TAB_Nb}}

Okay..., I guess your Line 26 is this one:
Code: Select all
SET !Sub_Str1 EVAL("var s=\"{{!EXTRACT}}\"; s.substr(VAR4,VAR5)")
And yep indeed, 'VAR4' and 'VAR5' in your 'EVAL()' are not defined, I reckon you mean to use '!VAR4' and '!VAR5':
Code: Select all
SET Sub_Str1 EVAL("var s=\"{{!EXTRACT}}\"; s.substr('{{!VAR4}}','{{!VAR5}}')")
PROMPT {{!Sub_Str1}}
or with the following Syntax that I prefer as it is easier to reuse for much more complex Expressions:
Code: Select all
SET Sub_Str1 EVAL("var s='{{!EXTRACT}}'; var v4='{{!VAR4}}', v5='{{!VAR5}}'; var z; z=s.substr(v4,v5); z;")
PROMPT {{Sub_Str1}}

And in both cases, I've removed the "!" in your '!Sub_Str1' to call your Var 'Sub_Str1' as "!" is reserved for Built-in Vars.

But the way you try to define '!VAR4' and '!VAR5' a bit earlier in your Script looks "strange" to me as well...:
Code: Select all
SET !VAR4 !VAR3 s.toString()
SET !VAR5 !VAR1.toString()

And when I say "as it is easier to reuse for much more complex Expressions", you can easily include your '!VAR4' and '!VAR5' Definitions in the same Statement, removing the need for those 2 "strange" Statements..:
Code: Select all
SET Sub_Str1 EVAL("var s='{{!EXTRACT}}'; var v4='{{!VAR3}}'.toString(), v5='{{!VAR1}}'.toString(); var z; z=s.substr(v4,v5); z;")
PROMPT {{Sub_Str1}}
- (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: Extract Data Using csv. & String Fn. Open Multi Tab

by Tamilselvan on Sat Jan 28, 2017 2:49 am

Worked perfectly !!! :D
Thank You Very much!
I need one more help.
when both the values are same, it works current tab only.
{!COL1}} and {{Sub_Str1}}
else another tab has moved and returned current tab.

it shows that the value (i.e. csv.file next content) is not available.

Entry [*/1-*] not available [Box has 126 entries], line: 13 (Error code: -924)

I need, if does not match, then move another tab once again repeat the task find and extract text :?: :idea:

Multi Tab.jpg

VERSION BUILD=9030808 RECORDER=FX
TAB T=1
SET !DATASOURCE "C:\\Users\\OFFICE\\Documents\\iMacros\\Datasources\\JobCard-No.csv"
SET !LOOP 2
SET !DATASOURCE_LINE {{!LOOP}}

'Select Beneficiary Job Card No.
TAG POS=1 TYPE=SELECT FORM=ID:aspnetForm ATTR=ID:ctl00_ContentPlaceHolder1_DDL_Registration CONTENT=%*{{!COL1}}*
WAIT SECONDS=1

SET !EXTRACT NULL
'Extract your Element:
TAG POS=1 TYPE=SELECT ATTR=NAME:ctl00$ContentPlaceHolder1$DDL_Registration EXTRACT=TXT
SET !VAR1 EVAL("var s=\"{{!COL1}}\"; s.length")
PROMPT {{!EXTRACT}}
SET !VAR3 17
PROMPT {{!COL1}}
PROMPT {{!VAR1}}
SET Sub_Str1 EVAL("var s='{{!EXTRACT}}'; var v4='{{!VAR3}}'.toString(), v5='{{!VAR1}}'.toString(); var z; z=s.substr(v4,v5); z;")
PROMPT {{Sub_Str1}}

'Spit out a "1" or "2" to reuse for "TAB T=n":
SET TAB_Nb EVAL("var s='{{Sub_Str1}}'; var z; if(s=='{{COL1}}'){z=1;} else{z=2;}; z;")
'Stay on TAB_1 if Element found or switch to TAB_2 if not found:
'TAB OPEN
TAB T={{TAB_Nb}}

I tried this method also

VERSION BUILD=9030808 RECORDER=FX
TAB T=1
SET !DATASOURCE "C:\\Users\\OFFICE\\Documents\\iMacros\\Datasources\\JobCard-No.csv"
SET !LOOP 2
SET !DATASOURCE_LINE {{!LOOP}}
TAG POS=1 TYPE=SELECT FORM=ID:aspnetForm ATTR=ID:ctl00_ContentPlaceHolder1_DDL_Registration CONTENT=%*{{!COL1}}*
WAIT SECONDS=1

'Spit out a "1" or "2" to reuse for "TAB T=n":
SET TAB_Nb EVAL("var s='{{COL1}}'; var z; if(s!='#EANF#'){z=1;} else{z=2;}; z;")
'Stay on TAB_1 if Element found or switch to TAB_2 if not found:
TAB T={{TAB_Nb}}

same error shown.
Multi Tab.jpg
.

when both the values are same, it works current tab only. (i.e) {!COL1}} = {{Sub_Str1}}
else another tab has moved and returned quickly to current tab.

I think while moving another tab consider as tab t=1. so that its show error
Entry [*/1-*] not available [Box has 126 entries], line: 13 (Error code: -924)
Tamilselvan
 
Posts: 36
Joined: Mon Mar 07, 2016 3:49 am

Re: Extract Data Using csv. & String Fn. Open Multi Tab

by Tamilselvan on Sun Feb 05, 2017 1:58 am

May I Use GOTO Line / GOTO Tab option?
Tamilselvan
 
Posts: 36
Joined: Mon Mar 07, 2016 3:49 am


Return to Data Extraction and Web Screen Scraping

Who is online

Users browsing this forum: No registered users and 1 guest

Website Monitoring