imacros javascript return top

2019-09-01 00:39发布

问题:

I'm writing a imacros script using javascript and I've a problem.

var result = "";
var Loop = 1;
while(true)
{    

iimSet("Loop",Loop);
var macro;
    macro="CODE:";
    macro +="SET !DATASOURCE site.csv" + "\n";
    macro +="SET !DATASOURCE_LINE {{Loop}}" + "\n";
    macro +="URL GOTO=https://www.google.com/search?q={{!COL1}}" + "\n";  
    macro +="WAIT SECONDS=1" + "\n";          
iimPlay(macro);

var ret_code = iimPlay("CODE:TAG POS=1 TYPE=DIV ATTR=ID:resultStats");
    if(ret_code<0){break;}
ret_code = iimPlay("CODE:TAG POS=1 TYPE=DIV ATTR=ID:resultStats EXTRACT=TXT");
    s = iimGetLastExtract();    
    result += " "+s;    
    Loop++
}
var Ru;
    Ru="CODE:";

iimPlay("#current.iim"); 

Here's the process. It loop throught the csv file and checks for how many pages are indexed in google results. Sometimes google asks to enter captcha. If captcha appears it breaks from 'var macro' and goes to 'var ru' which is for captcha part. After entering the captcha I need to return to 'var macro' and continue from where it left. And also I need to set a loop to datasource to stop everything. Can't seem to figure this out. Looking for your help.

Thank you, Mark.

回答1:

So, you may try something like this:

for the 1st issue:

// ...
var ret_code = iimPlay("CODE:TAG POS=1 TYPE=DIV ATTR=ID:resultStats");
if (ret_code < 0)
    iimPlay("#current.iim");
iimPlay("CODE:TAG POS=1 TYPE=DIV ATTR=ID:resultStats");
ret_code = iimPlay("CODE:TAG POS=1 TYPE=DIV ATTR=ID:resultStats EXTRACT=TXT");
// ...

for the 2nd issue:

// ...
    macro +="WAIT SECONDS=1" + "\n";          
var ret_code = iimPlay(macro);
if (ret_code < 0)
    break;
// ...