Loop trough select options

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
artilibere
Posts: 3
Joined: Wed Jun 29, 2011 11:27 am

Loop trough select options

Post by artilibere » Wed Jun 29, 2011 11:36 am

Hi all,
I'm a neewbie and I cannot get how to loop a sample of code basing on a select option.

There's my code:
------------------- CODE START -------------
VERSION BUILD=7220523 RECORDER=FX
TAB T=1
TAB CLOSEALLOTHERS

URL GOTO=http://www.asl.milano.it/user/Default.a ... Z=9&PAG=85
TAG POS=1 TYPE=DIV ATTR=TXT:Categoria:<SP>--<SP>SELEZIONA<SP>--<SP>Medico<SP>Generico<SP>Pediatra

---- LOOP START
SAVEAS TYPE=CPL FOLDER=* FILE=+_{{!NOW:yyyymmdd_hhnnss}}
TAG POS=1 TYPE=SELECT FORM=NAME:aspnetForm ATTR=ID:ctl00_phContent_ctl00_GridViewElencoMedici_ctl13_ddlPageSelector CONTENT=%1
TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:aspnetForm ATTR=ID:ctl00_phContent_ctl00_GridViewElencoMedici_ctl13_BTNGo
---- LOOP END
------------------- CODE END -------------

I simply want to automate that procedure, looping around a variable $v starting from 1 to 10:

(1) save the current page in $v.html
(2) go to selector "ctl00_phContent_ctl00_GridViewElencoMedici_ctl13_ddlPageSelector"
(3) select option ($v+1)
(4) click to "ctl00_phContent_ctl00_GridViewElencoMedici_ctl13_BTNGo"
(5) when page is reloaded, increment $v and start again from (1)

Someone can give me some hint?

Thank you,
Carlo
Tom, Tech Support
Posts: 3529
Joined: Mon May 31, 2010 4:59 pm

Re: Loop trough select options

Post by Tom, Tech Support » Sat Jul 02, 2011 11:40 am

Hello Carlo,

Something appears to be missing from the macro code you provided. If I navigate to this page:

http://www.asl.milano.it/user/Default.a ... Z=9&PAG=85

there is no SELECT element on this page with an ID attribute value of ctl00_phContent_ctl00_GridViewElencoMedici_ctl13_ddlPageSelector.

Please provide the necessary steps to navigate to the page with this drop-down field.
Regards,

Tom, iMacros Support
artilibere
Posts: 3
Joined: Wed Jun 29, 2011 11:27 am

Re: Loop trough select options

Post by artilibere » Sat Jul 02, 2011 2:19 pm

Hello Tom,
sorry for incomplete request: you have to hit 'Cerca' (Search) one first time to see the page I'm talking about.
Thanks a lot.
Tom, Tech Support
Posts: 3529
Joined: Mon May 31, 2010 4:59 pm

Re: Loop trough select options

Post by Tom, Tech Support » Sat Jul 02, 2011 3:22 pm

Hi Carlo,

You need two separate macros. The first macro just navigates to the page and clicks Cerca:

Code: Select all

VERSION BUILD=7220523 RECORDER=FX
TAB T=1
TAB CLOSEALLOTHERS
URL GOTO=http://www.asl.milano.it/user/Default.aspx?MOD=MEDFND&SEZ=9&PAG=85
TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:aspnetForm ATTR=ID:ctl00_phContent_ctl00_BTNCerca
Then you run the second macro in loop mode. Set the Max. value on the Play tab of the iMacros sidebar to the number of times you want to loop, and then use the Play (Loop) button to play the following macro:

Code: Select all

SAVEAS TYPE=CPL FOLDER=* FILE={{!LOOP}}.html
TAG POS=1 TYPE=SELECT FORM=NAME:aspnetForm ATTR=ID:ctl00_phContent_ctl00_GridViewElencoMedici_ctl13_ddlPageSelector CONTENT=%{{!LOOP}}
TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:aspnetForm ATTR=ID:ctl00_phContent_ctl00_GridViewElencoMedici_ctl13_BTNGo
Regards,

Tom, iMacros Support
Post Reply