简体   繁体   English

Javascript iMacros嵌套了while循环(宏中有两个循环)

[英]Javascript iMacros nested while loop (two loops in macro)

I have been trying to get a loop inside of a loop to work. 我一直在尝试使循环在循环中起作用。 By that I mean I'm going to multiple pages in a website, clicking all the links in a table and extraction information from the next page after following the link. 我的意思是说,我将转到一个网站的多个页面,单击表格中的所有链接,并在链接之后从下一页中提取信息。 I've found this question here http://www.stackoverflow.com/questions/18402012/nested-loop-in-imacros-2nd-loop , yet I can not get it to work for me. 我在这里http://www.stackoverflow.com/questions/18402012/nested-loop-in-imacros-2nd-loop找到了这个问题,但我无法为我工作。 The problem is happening at the "while(true)" or "n = 1" section I think. 我认为问题发生在“ while(true)”或“ n = 1”部分。 My code looks this: 我的代码看起来像这样:

const L = "\n";

var macro;
macro = "CODE:";
macro += "SET !ERRORIGNORE YES" + L; 
macro += "SET !DATASOURCE DailyCitySummaries.csv" + L;
macro += "SET !DATASOURCE_LINE {{i}}" + L; 
macro += "SET !WAITPAGECOMPLETE YES" + L; 
macro += "SET !EXTRACT_TEST_POPUP NO" + L; 
macro += "URL GOTO=http://{{!COL1}}" + L;
macro += "FRAME F=0" + L;
macro += "TAG POS=1 TYPE=A ATTR=HREF:/page/Results.cfm?type=location=* EXTRACT=TXT" + L; 
macro += "SAVEAS TYPE=EXTRACT FOLDER=/root/Desktop/ FILE=CityName.txt" + L; 

var macro1;
macro1 = "CODE:";
macro1 += "TAG POS=1 TYPE=A ATTR=TXT:city<SP>{{n}}" + L;
macro1 += "TAG POS=1 TYPE=STRONG ATTR=TXT:city<SP>* EXTRACT=TXT" + L; 
macro1 += "TAG POS=1 TYPE=TABLE ATTR=TXT:* EXTRACT=TXT" + L; 
macro1 += "SAVEAS TYPE=EXTRACT FOLDER=/root/Desktop FILE=CityDetails.csv" + L;

for (var i=1;i < 19;i++) 
{
iimSet("i", i);
iimPlay(macro)

     //set counter
    var n = 1   //this is only following the first link, I want all of them!
    while(true)   //this is suppose to be an infinite loop 
        {
        iimSet("n", n)
        var ret=iimPlay(macro1);
//kill loop when it comes to end and go to next location (first macro)
        if(ret<0) 
            {
            break;
            }
//increase counter
        n++;
        } //end of while loop
} //end of for loop

Is it my formating or something. 是我的格式或其他内容。 What the code does now is go to the web page, extract a table, click a link in the overview table, go to a detail page for that link, then extract a table for the detail page. 代码现在要做的是转到网页,提取一个表,单击概述表中的链接,转到该链接的详细信息页面,然后为该详细信息页面提取一个表。 The problem is, it's not clicking all the links in the overview table, only the first one, and then it goes through the first loop for the next overview table. 问题在于,它没有单击概述表中的所有链接,仅单击了第一个链接,然后单击了下一个概述表的第一个循环。 The number of links is different for every overview table. 每个概述表的链接数都不相同。 I know didely about JavaScript, so any pointers would be greatly appreciated. 我对JavaScript非常了解,因此任何指针都将不胜感激。

In case anyone wants to see the code in what ended up working: 如果有人希望看到最终运行的代码:

const L = "\n";

var macro;
macro = "CODE:";
macro += "SET !ERRORIGNORE YES" + L; 
macro += "SET !DATASOURCE DailyCitySummaries.csv" + L;
macro += "SET !DATASOURCE_LINE {{i}}" + L; 
macro += "SET !WAITPAGECOMPLETE YES" + L; 
macro += "SET !EXTRACT_TEST_POPUP NO" + L; 
macro += "URL GOTO=http://{{!COL1}}" + L;
macro += "FRAME F=0" + L;
macro += "TAG POS=1 TYPE=A ATTR=HREF:/page/Results.cfm?type=location=* EXTRACT=TXT" + L; 
macro += "SAVEAS TYPE=EXTRACT FOLDER=/root/Desktop/ FILE=CityName.txt" + L; 

var macro1;
macro1 = "CODE:";
macro1 += "TAG POS=1 TYPE=A ATTR=TXT:city<SP>{{n}}" + L;
macro1 += "TAG POS=1 TYPE=STRONG ATTR=TXT:city<SP>* EXTRACT=TXT" + L; 
macro1 += "TAG POS=1 TYPE=TABLE ATTR=TXT:* EXTRACT=TXT" + L; 
macro1 += "SAVEAS TYPE=EXTRACT FOLDER=/root/Desktop FILE=CityDetails.csv" + L;
macro1 += "BACK" + L;   // The difference that made a difference

for (var i=1;i < 19;i++) 
{
iimSet("i", i);
iimPlay(macro)

     //set counter
    var n = 1 
    while(true)   //this is an infinite loop 
        {
        iimSet("n", n)
        var ret=iimPlay(macro1);
//kill loop when it comes to end and go to next location (first macro)
        if(ret<0) 
            {
            break;
            }
//increase counter
        n++;
        } //end of while loop
} //end of for loop

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM