希望你能帮助我使用iMacros进行嵌套循环。
经过大量的工作,我觉得我终于到了某个地方:
脚本中的问题是我无法获取循环{{n}}
来获取页面的所有位置(列表项)。
任何帮助都将受到高度赞赏。
var macro;
macro = "CODE:";
macro += "VERSION BUILD=000000" + "\n";
macro += "TAB T=1" + "\n";
macro += "SET !ERRORIGNORE YES" + "\n";
macro += "SET !EXTRACT_TEST_POPUP NO" + "\n";
macro += "SET !DATASOURCE source.csv" + "\n";
macro += "SET !DATASOURCE_COLUMNS 1 " + "\n";
macro += "SET !LOOP 1" + "\n";
//macro += "SET !TIMEOUT 3" + "\n";
macro += "SET !DATASOURCE_LINE {{i}}" + "\n";
macro += "URL GOTO=http://site.com/?what={{!COL1}} " + "\n";
macro += "TAG POS={{n}} TYPE=LI ATTR=CLASS:classofdiv" + "\n";
macro += "TAG POS={{n}} TYPE=SPAN ATTR=TXT:* EXTRACT=TXT" + "\n";
macro += "SAVEAS TYPE=EXTRACT FOLDER=* FILE=All_list_items.txt" + "\n";
for (var i=1;i<20;i++)
{
iimSet("i",i)
iimPlay(macro)
iimSet("n",i)//<-- How to grab all the TAG POS of the website?
}
编辑1.1 - 我应该指出我使用术语{{n}}
作为示例来循环列表项(div-ul-li-span)。如果替换为&#39; POS = 1&#39;该脚本有效,但当然只保存第一个列表项而不是所有列表项。
答案 0 :(得分:2)
所以你想抓住POS = x的所有位置?
试试这个:
var macro;
macro = "CODE:";
macro += "VERSION BUILD=000000" + "\n";
macro += "TAB T=1" + "\n";
macro += "SET !ERRORIGNORE YES" + "\n";
macro += "SET !EXTRACT_TEST_POPUP NO" + "\n";
macro += "SET !DATASOURCE source.csv" + "\n";
macro += "SET !DATASOURCE_COLUMNS 1 " + "\n";
macro += "SET !LOOP 1" + "\n";
//macro += "SET !TIMEOUT 3" + "\n";
macro += "SET !DATASOURCE_LINE {{i}}" + "\n";
macro += "URL GOTO=http://site.com/?what={{!COL1}} " + "\n";
var macro1;
macro1 = "CODE:";
macro1 += "TAG POS={{n}} TYPE=LI ATTR=CLASS:classofdiv" + "\n";
macro1 += "TAG POS={{n}} TYPE=SPAN ATTR=TXT:* EXTRACT=TXT" + "\n";
macro1 += "SAVEAS TYPE=EXTRACT FOLDER=* FILE=All_list_items.txt" + "\n";
for (var i=1;i<20;i++)
{
iimSet("i",i)
iimPlay(macro)
//set counter
var n=1;
//this is infinite loop
while(true)
{
iimSet("n",n)//<-- How to grab all the TAG POS of the website?
var ret=iimPlay(macro1);
//if macro didn't find any more positions it breaks from this loop
//and reads new link from the csv file
if(ret<0)
{
break;
}
//increase counter
n++;
}//end of while loop
}//end of for loop
只要每次都有新位置,这将使macro1在循环内循环。这可能不起作用所以给我们反馈。