2

希望您能帮助我使用 iMacros 制作嵌套循环。

  1. 第一个循环:循环 source.csv 的所有行(col A,多行)
  2. 第二个循环(X):获取在 hxxp://site.com/?what={{!COL1}} 上找到的所有 List 元素

经过大量的工作,我觉得我终于到达了某个地方:

脚本中的问题是我无法让 Loop{{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)。如果用 'POS=1' 替换,脚本可以工作,但当然只保存第一个列表项而不是所有列表项。

4

1 回答 1

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

只要每次都有新位置,这将使宏 1 能够在 while 循环内循环。这可能不起作用,所以给我们反馈。

于 2013-08-26T00:16:13.353 回答