我需要获取网站中可用的列表项,该列表项以分页样式列出项目。我将提取每个页面上项目的信息。我使用 编写了一个 Javascript 代码settimeout(function(){...code...}, 5000)
,并在 Firefox Web 控制台中运行此代码。脚本获取页面中的所有项目,一旦完成,脚本通过执行click()
超链接“next”的方法提交页面。这将一直持续到页面中有“下一页”超链接(在最后一页中只有“后退”超链接,如果存在)。在提交的每个页面上,我都会将其超时为 5 秒。
我在 Firefox Web 控制台中执行了这段代码,成功运行并获取了第一页的结果,然后提交了页面,下一页也加载了。但是,问题是,一旦提交页面,脚本就会停止。即使在下一页加载后如何连续运行此脚本?有没有其他方法可以实现这个功能?
var inc=0;
var ids;
var main=function(){
console.log("attempiting..............."+inc);
var i=0;
{
ids[inc]=b();//function, fetch the items from the page
console.log(ids);
var more=document.getElementById("m_more_item");
if(more){
//next link is there
var cli=more.getElementsByTagName("a");
console.log("navigating to next page "+cli[0]);
inc++;
setTimeout(main,5000); //I tried placing this after click, but didnt work!
cli[0].click(); //submitting...
} else {
//last page reached, exiting...
console.log("exit1-> total items fetched are: "+ids);
return ids;
}
}
};
main();