Please give me an example of IMacros macros to visit all site entirely
So I give the first page and macros must visit all pages of this site. (open a new tab for example of each page)
This one I found in the net, but this macros visit only links in one starting page, and not visit the second level in deep.
Thank you for the help!
//imacros-js:showsteps no
//Testing forum post http://forum.iopus.com/viewtopic.php?f=11&t=7537&sid=2103c60e70f9c7051dcda5264874a488
//Idea is to read something in common on the page and open each link in a new tab.
var macro, retcode, url="", pos=1, stop=false;
while(!stop)
{
macro="CODE:";
macro+="TAB T=1\n";
//macro+="TAG POS="+pos+" TYPE=A EXTRACT=HREF\n";
macro+="TAG POS="+pos+" TYPE=A ATTR=HREF:* EXTRACT=HREF\n";
//ATTR=CLASS:*topictitle*
retcode = iimPlay(macro);
if (retcode < 0) // an error has occured
{
errtext = iimGetLastError();
alert("1st Error "+retcode+": "+errtext);
stop=true;
}
//Stop if extract found nothing 开发者_如何学运维or counter is too high as a precaution
if((url = iimGetLastExtract()) == "#EANF#" || pos > 10000)
{
stop=true;
break;
}
else
{
macro="CODE:";
macro+="SET !TIMEOUT 15\n";
macro+="SET !ERRORIGNORE YES\n";
macro+="TAB T=1\n";
macro+="TAB NEW OPEN\n";
macro+="TAB T="+new Number(pos+1)+"\n";
macro+="URL GOTO="+url+"\n";
macro+="TAB T=1\n";
retcode = iimPlay(macro);
if (retcode < 0) // an error has occured
{
errtext = iimGetLastError();
alert("2nd Error "+retcode+": "+errtext);
stop=true;
}
pos++;
}
}
This code basically finds all the links on the page. Then it extracts the href, and constructs a new macro in the variable macro. Wich it then runs with the last command retcode = iimPlay(macro)
What you want is a recursive function, which not only opens a new tab for the href its finds but also runs the same function on the page its points to.
So you should make the above code into a function which accepts a URL as a parameter. And then when imacros finds and link, call the function with the links href.
精彩评论