javascript recursive loops for imacros

305 Views Asked by At

I'm hoping that somebody can help me with a problem I'm having with a JavaScript code written for iMacros. There is a site that I'm extracting information from that has the format of three pages, with every page providing more details of the same event then the prior page. So page one has a list of links for events of the day, page two has the details of that event, and page three has details of the people participating in the event. The problem is I can't figure out how to go to page two and loop through all the links pointing to the third page. Right now the code that I've come up is going to all the page twos, but only going to one person for the third page per an event. That is, go to Event 1, extract the first person, go to Event 2,extract the second person, etc.

const L = "\n";
EventsSummary = "CODE:";    //Go to Event Summaries
EventsSummary += "SET !ERRORIGNORE YES" + L; 
EventsSummary += "SET !DATASOURCE DailyEventSummaries.csv" + L; 
EventsSummary += "SET !DATASOURCE_LINE {{loop}}" + L; 
EventsSummary += "SET !WAITPAGECOMPLETE YES" + L; 
EventsSummary += "SET !EXTRACT_TEST_POPUP NO" + L;
EventsSummary += "WAIT SECONDS=10" + L;
EventsSummary += "URL GOTO=http://{{!COL1}}" + L;
EventsSummary += "FRAME F=0" + L;
EventsSummary += "TAG POS=1 TYPE=A ATTR=HREF:/profiles/Events.cfm?type=City=* EXTRACT=TXT" + L;
EventsSummary += "SAVEAS TYPE=EXTRACT FOLDER=/root/Desktop/ FILE=CityName.txt" + L;
EventsSummary += "TAG POS=1 TYPE=TABLE ATTR=TXT:* EXTRACT=TXT" + L; 
EventsSummary += "SAVEAS TYPE=EXTRACT FOLDER=/root/Desktop/ FILE=CityEventTable.csv" + L;
//Click on Event Details and extract
EventDetails = "CODE:";
EventDetails += "TAG POS=1 TYPE=A ATTR=TXT:Event<SP>{{n}}" + L;
EventDetails += "TAG POS=1 TYPE=STRONG ATTR=TXT:Event<SP>* EXTRACT=TXT" + L;
EventDetails += "TAG POS=1 TYPE=TABLE ATTR=TXT:* EXTRACT=TXT" + L; 
EventDetails += "SAVEAS TYPE=EXTRACT FOLDER=/root/Desktop/ FILE=EventDetails.csv" + L;
EventDetails += "TAG POS=1 TYPE=P ATTR=TXT:Managers:* EXTRACT=TXT" + L; 
EventDetails += "SAVEAS TYPE=EXTRACT FOLDER=/root/Desktop/ FILE=Managers.csv" + L;
EventDetails += "TAG POS=1 TYPE=P ATTR=TXT:Trainers:* EXTRACT=TXT" + L; 
EventDetails += "SAVEAS TYPE=EXTRACT FOLDER=/root/Desktop/FILE=Trainers.csv" + L;
EventDetails += "WAIT SECONDS=5" + L;
//Get Person Details
EventDetails += "TAG POS={{h}} TYPE=A ATTR=HREF:http://www.somesite.com/profiles/Events.=*" + L;
EventDetails += "TAG POS=3 TYPE=STRONG ATTR=* EXTRACT=TXT" + L;
EventDetails += 'TAG XPATH="//div[3]/div/table/tbody" EXTRACT=TXT' + L;
EventDetails += "SAVEAS TYPE=EXTRACT FOLDER=/root/Desktop FILE=leadresults.csv" + L;
EventDetails += "WAIT SECONDS=3" + L;
EventDetails += "BACK" + L; //Go Back to EventDetails
EventDetails += "BACK" + L; //Go Back to the EventsSummary
for (i = 1; i < 69; i++) {    //Extract EventsSummary,go to Event Details
    iimSet("loop", i);
    iimPlay(EventsSummary);
    var n = 1  //set counter
    var h = 1
    while(true) {    //infinite loop
        iimSet("n", n)
        iimSet("h", h)
        var ret=iimPlay(EventDetails);
        if(ret<0)   //kill loop when comes to an end 
            {
            break;
            }
        n++; //event loop   //increase counter
        h++; //person loop
        } //end of while loop
            } //end for loop 
iimPlayCode("TAB CLOSE" + L ); //Exit 

I apologize for the all the details if they seem excessive. To be clear, I'm trying to go to one page, loop through all the links, then go back to the prior page, click on the second link, then extract all the links on that page. Any ideas?

0

There are 0 best solutions below