Replace Text From Extract

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

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
BrooklynGuy
Posts: 6
Joined: Fri Jun 07, 2019 5:51 pm

Replace Text From Extract

Post by BrooklynGuy » Tue Jun 11, 2019 8:30 pm

Hi All,

I am extracting HTM and getting the following result:

<select name="vehicleStyle" tabindex="5" class="form-control selectwidthauto selectnormalheight" id="vehicleStyle" style="border: 1px solid green; background-color: white;" onchange="javascript:vehicleStyleChanged(this.options[this.selectedIndex].value, this.options[this.selectedIndex].text);setTimeout('__doPostBack(\'vehicleStyle\',\'\')', 0)"><option style="background-color: lightblue;" value="">Select Style</option><option value="340979001">84419 4dr Wgn Pure</option><option value="340979002">84619 4dr Wgn Luxe</option> </select>

I would like to replace the following text with the number "2019,"

<select name="vehicleStyle" tabindex="5" class="form-control selectwidthauto selectnormalheight" id="vehicleStyle" style="border: 1px solid green; background-color: white;" onchange="javascript:vehicleStyleChanged(this.options[this.selectedIndex].value, this.options[this.selectedIndex].text);setTimeout('__doPostBack(\'vehicleStyle\',\'\')', 0)"><option style="background-color: lightblue;" value="">Select Style</option><option value="

And then replace

"> with a comma

Then

</option><option value="

with a"2019,"

and delete the trailing

</option> </select>

Can anyone help me here?
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Replace Text From Extract

Post by chivracq » Wed Jun 12, 2019 2:50 am

BrooklynGuy wrote:
Tue Jun 11, 2019 8:30 pm
Hi All,

I am extracting HTM and getting the following result:

Code: Select all

<select name="vehicleStyle" tabindex="5" class="form-control selectwidthauto selectnormalheight" id="vehicleStyle"
 style="border: 1px solid green; background-color: white;"
  onchange="javascript:vehicleStyleChanged(this.options[this.selectedIndex].value,
   this.options[this.selectedIndex].text);setTimeout('__doPostBack(\'vehicleStyle\',\'\')', 0)">
  <option style="background-color: lightblue;"   value="">Select Style</option>
   <option value="340979001">84419 4dr Wgn Pure</option>
   <option value="340979002">84619 4dr Wgn Luxe</option>      </select>
I would like to replace the following text with the number "2019,"

Code: Select all

<select name="vehicleStyle" tabindex="5" class="form-control selectwidthauto selectnormalheight" id="vehicleStyle"
 style="border: 1px solid green; background-color: white;"
  onchange="javascript:vehicleStyleChanged(this.options[this.selectedIndex].value,
   this.options[this.selectedIndex].text);setTimeout('__doPostBack(\'vehicleStyle\',\'\')', 0)">
  <option style="background-color: lightblue;" value="">Select Style</option>
  <option value="
And then replace

"> with a comma

Then

</option><option value="

with a"2019,"

and delete the trailing

</option> </select>

Can anyone help me here?
"Can anyone help me here?"
=> CIM...! :mrgreen: (Read my Sig...)
Might speed up "the Process" if you read the Forum Rules, when you join a (Technical) Forum... :idea:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
BrooklynGuy
Posts: 6
Joined: Fri Jun 07, 2019 5:51 pm

Re: Replace Text From Extract

Post by BrooklynGuy » Wed Jun 12, 2019 3:44 pm

SET !EXTRACT_TEST_POPUP NO
VERSION BUILD=10022823
TAB T=1
TAB CLOSEALLOTHERS
FRAME NAME=BODY
'Uses a Windows script to submit several datasets to a website, e. g. for filling an online database
' Specify input file (if !COL variables are used, IIM automatically assume a CSV format of the input file
'CSV = Comma Separated Values in each line of the file
SET !DATASOURCE ModelID.txt
'Start at line 2 to skip the header in the file
SET !LOOP 1
'Increase the current position in the file with each loop
SET !DATASOURCE_LINE {{!LOOP}}
' Fill web form
TAG POS=1 TYPE=SELECT FORM=NAME:ChangeAuto ATTR=NAME:vehicleYear CONTENT=%{{!COL1}}
TAG POS=1 TYPE=SELECT ATTR=NAME:vehicleYear EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=C:\PackageFeed FILE=StyleID.txt
WAIT SECONDS=1
TAG POS=1 TYPE=SELECT FORM=NAME:ChangeAuto ATTR=NAME:vehicleMake CONTENT=%{{!COL2}}
TAG POS=1 TYPE=SELECT ATTR=NAME:vehicleMake EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=C:\PackageFeed FILE=StyleID.txt
WAIT SECONDS=1
TAG POS=1 TYPE=SELECT FORM=NAME:ChangeAuto ATTR=NAME:vehicleModel CONTENT=%{{!COL4}}
TAG POS=1 TYPE=SELECT ATTR=NAME:vehicleModel EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=C:\PackageFeed FILE=StyleID.txt
WAIT SECONDS=1
TAG POS=1 TYPE=SELECT ATTR=NAME:vehicleStyle EXTRACT=HTM
SAVEAS TYPE=EXTRACT FOLDER=C:\PackageFeed FILE=StyleID.txt
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Replace Text From Extract

Post by chivracq » Wed Jun 12, 2019 3:59 pm

And...?, any Follow-up...? It shouldn't be very difficult to mention 3 Versions about your FCI, I would think...

But OK, I read your Post and I "finally" understood what you want, well..., I think...! 8)
So if I'm correct, the "Final Result" that you want is the following:

Code: Select all

2019,340979001,84419 4dr Wgn Pure
2019,340979002,84619 4dr Wgn Luxe
Then, yep, OK, several ways to do that... And it's not very-very complicated... :D

And there might be some much easier way than the way you've "chosen" a bit, even if you didn't post any Script, if you can post the URL to that Site/Page...?

And I would have some further Qt's, if you will always have 2 Entries in the DDLB...?, and if you are "sure" you want the 'Value' ("340979001" + "340979002")...?, but OK, follow up and mention your FCI first...

>>>

EDIT:
Ah...!, good, you are "busy" while I was typing my own Reply...:
BrooklynGuy wrote:
Wed Jun 12, 2019 3:44 pm

Code: Select all

SET !EXTRACT_TEST_POPUP NO
VERSION BUILD=10022823
TAB T=1
TAB CLOSEALLOTHERS
FRAME NAME=BODY
'Uses a Windows script to submit several datasets to a website, e. g. for filling an online database
' Specify input file (if !COL variables are used, IIM automatically assume a CSV format of the input file
'CSV = Comma Separated Values in each line of the file
SET !DATASOURCE ModelID.txt
'Start at line 2 to skip the header in the file
SET !LOOP 1
'Increase the current position in the file with each loop 
SET !DATASOURCE_LINE {{!LOOP}}
' Fill web form  
TAG POS=1 TYPE=SELECT FORM=NAME:ChangeAuto ATTR=NAME:vehicleYear CONTENT=%{{!COL1}}
TAG POS=1 TYPE=SELECT ATTR=NAME:vehicleYear EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=C:\PackageFeed FILE=StyleID.txt
WAIT SECONDS=1
TAG POS=1 TYPE=SELECT FORM=NAME:ChangeAuto ATTR=NAME:vehicleMake CONTENT=%{{!COL2}}
TAG POS=1 TYPE=SELECT ATTR=NAME:vehicleMake EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=C:\PackageFeed FILE=StyleID.txt
WAIT SECONDS=1
TAG POS=1 TYPE=SELECT FORM=NAME:ChangeAuto ATTR=NAME:vehicleModel CONTENT=%{{!COL4}}
TAG POS=1 TYPE=SELECT ATTR=NAME:vehicleModel EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=C:\PackageFeed FILE=StyleID.txt
WAIT SECONDS=1
TAG POS=1 TYPE=SELECT ATTR=NAME:vehicleStyle EXTRACT=HTM
SAVEAS TYPE=EXTRACT FOLDER=C:\PackageFeed FILE=StyleID.txt
But, pfff..., FCI still not mentioned (clearly)... :roll: :
=>iMacros for FF v10.0.2...?, 'PE'(?), FF v...?, or iMB v10.0.2...?, OS=Win...?
Last edited by chivracq on Wed Jun 12, 2019 4:07 pm, edited 1 time in total.
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
BrooklynGuy
Posts: 6
Joined: Fri Jun 07, 2019 5:51 pm

Re: Replace Text From Extract

Post by BrooklynGuy » Wed Jun 12, 2019 4:06 pm

Sorry just new here, trying to figure this all out.

iMacros Browser (x86) Version 10.0.2.2823
Enterprise Edition

Ultimate desired result would be:

2019,INFINITI,QX60 AWD 19.5,340979001,84419 4dr Wgn Pure
2019,INFINITI,QX60 AWD 19.5,340979002,84619 4dr Wgn Luxe

The first 3 columns are the first 3 TXT extracts.
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Replace Text From Extract

Post by chivracq » Wed Jun 12, 2019 4:22 pm

BrooklynGuy wrote:
Wed Jun 12, 2019 4:06 pm
Sorry just new here, trying to figure this all out.

Code: Select all

iMacros Browser (x86) Version 10.0.2.2823
Enterprise Edition
Ultimate desired result would be:

Code: Select all

2019,INFINITI,QX60 AWD 19.5,340979001,84419 4dr Wgn Pure
2019,INFINITI,QX60 AWD 19.5,340979002,84619 4dr Wgn Luxe
The first 3 columns are the first 3 TXT extracts.
OK, good, we finally have your FCI...! (Even if OS is still missing, but OK, never mind...)

So..., will you always have 2x 'vehicleStyle' Entries in the DDLB...?, or is that Nb variable...?, and in which Range...?

In this current Case where you have 2 Entries, do you want them both in one same Cell (in 1 Row) when you'll be opening your '.CSV' in 'Excel' for example, or do you want the Data in 5 Cells (in 1 Row)...?, or do you want the Data in 10 Cells (in 2 Rows)...? Oh...!, or also possible is 2 Cells (in 2 Rows)...?
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
BrooklynGuy
Posts: 6
Joined: Fri Jun 07, 2019 5:51 pm

Re: Replace Text From Extract

Post by BrooklynGuy » Wed Jun 12, 2019 4:33 pm

Windows 8.1 Pro

It would be best, 2 rows with 5 columns.
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Replace Text From Extract

Post by chivracq » Wed Jun 12, 2019 6:11 pm

BrooklynGuy wrote:
Wed Jun 12, 2019 4:33 pm

Code: Select all

Windows 8.1 Pro
It would be best, 2 rows with 5 columns.
OK, and you didn't answer if you will always have 2 Entries in the DDLB, or if that Nb could be variable, but your current Script would then become stg like:

Code: Select all

VERSION BUILD=10022823
SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 0
SET !EXTRACT_TEST_POPUP NO
TAB T=1
TAB CLOSEALLOTHERS

'Uses a Windows script to submit several datasets to a website, e. g. for filling an online database
' Specify input file (if !COL variables are used, IIM automatically assume a CSV format of the input file
'CSV = Comma Separated Values in each line of the file
SET !DATASOURCE ModelID.txt
'Start at line 2 to skip the header in the file
SET !LOOP 1
'Increase the current position in the file with each loop 
SET !DATASOURCE_LINE {{!LOOP}}

' Fill web form  
FRAME NAME=BODY
TAG POS=1 TYPE=SELECT FORM=NAME:ChangeAuto ATTR=NAME:vehicleYear CONTENT=%{{!COL1}}
SET !EXTRACT NULL
TAG POS=1 TYPE=SELECT ATTR=NAME:vehicleYear EXTRACT=TXT
SET Vehicle_Year {{!EXTRACT}}
WAIT SECONDS=1

TAG POS=1 TYPE=SELECT FORM=NAME:ChangeAuto ATTR=NAME:vehicleMake CONTENT=%{{!COL2}}
SET !EXTRACT NULL
TAG POS=1 TYPE=SELECT ATTR=NAME:vehicleMake EXTRACT=TXT
SET Vehicle_Make {{!EXTRACT}}
WAIT SECONDS=1

TAG POS=1 TYPE=SELECT FORM=NAME:ChangeAuto ATTR=NAME:vehicleModel CONTENT=%{{!COL4}}
SET !EXTRACT NULL
TAG POS=1 TYPE=SELECT ATTR=NAME:vehicleModel EXTRACT=TXT
SET Vehicle_Model {{!EXTRACT}}
WAIT SECONDS=1

'Extract 1st 'Vehicle_Style' Entry from DDLB:
TAG POS=1 TYPE=OPTION ATTR=TXT:Select<SP>Style EXTRACT=TXT
SET !EXTRACT NULL
TAG POS=R1 TYPE=OPTION ATTR=TXT:* EXTRACT=TXT
SET Vehicle_Style_1 {{!EXTRACT}}
'>
SET !EXTRACT NULL
TAG POS=1 TYPE=OPTION ATTR=TXT:{{Vehicle_Style_1}} EXTRACT=HTM
SET Vehicle_Style_1_Value EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split('value="'); y=x[1].split('">'); z=y[0]; z;")
'>
'Save 1st Entry:
SET !EXTRACT {{Vehicle_Year}}[EXTRACT]{{Vehicle_Make}}[EXTRACT]{{Vehicle_Model}}[EXTRACT]{{Vehicle_Style_1_Value}}[EXTRACT]{{Vehicle_Style_1}}
SAVEAS TYPE=EXTRACT FOLDER=C:\PackageFeed FILE=StyleID.txt

'Extract 2nd 'Vehicle_Style' Entry from DDLB:
'=> Same like 1st Entry, with 'POS=R2'...
And you do the same for the 2nd 'Vehicle_Style' Entry, by only changing the 'POS=R1' to 'POS=R2', and adapting the "1" in the Names for the Vars to "2" of course if you want the Vars to have "clean" Names... Hum, yes you DO need to adapt the Names, because the 'Vehicle_Style_[1-2]' Var is reused as Attribute to then extract its corresponding Value...

The Double Quote in the 2x 'split()' in the 'EVAL()' might need to be escaped, I'm not sure and I cannot test as you didn't provide the URL, if that's the case, then the 'EVAL()' will become:

Code: Select all

SET Vehicle_Style_1_Value EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split('value=\"'); y=x[1].split('\">'); z=y[0]; z;")
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
BrooklynGuy
Posts: 6
Joined: Fri Jun 07, 2019 5:51 pm

Re: Replace Text From Extract

Post by BrooklynGuy » Wed Jun 12, 2019 10:24 pm

Works great!

Thanks for your help!
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Replace Text From Extract

Post by chivracq » Wed Jun 12, 2019 10:34 pm

BrooklynGuy wrote:
Wed Jun 12, 2019 10:24 pm
Works great!

Thanks for your help!
Ah, OK...! You could have posted the "full" Final Script..., and mentioned if the Double Quote in each 'split()' needed to be escaped of not...
And I "hope" you understood the "Mechanism" I implemented to extract the 2 'Vehicle_Style' DDLB Entries, together with their corresponding 'Value' Attribute...

But OK, glad it works (directly), enjoy...! 8)
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
Post Reply