I need to fetch a list items available in a website that list the items in paging style. I will extract information of the items on each pages. I wrote a Javascript code using a settimeout(function(){...code...}, 5000)
, and run this code in the Firefox web console. The script fetches all the items in the page, once this is done, the script submits the page by executing click()
method of the hyperlink "next". this will continue till the page has "Next" hyperlink in the page (in last page only "back" hyperlink if present). On every page submit I timeout it to 5 seconds.
I executed this code in the Firefox web console, this run successfully and fetches the first pages results, then submits the page, the next page too loads. But, the problem is, once the page is submitted the script stops. How to run this script continuously even after the next page load? Is there any other way to achieve this functionality?
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();