I would like to take screenshot of many pages using phantomjs.
The problem is how to deal if I have more pages than 1000 because at the present moment following code crashes phantomjs:
This is an example of aobj:
var aobj = '[{"kb":21.047829999999976,"jb":52.174250000000015,"ff":110.16456426650427},{"kb":21.047997078651633,"jb":52.17421235955058,"ff":110.16456426650427},{"kb":21.048164157303404,"jb":52.17417471910114,"ff":110.16456426650427},{"kb":21.04833123595506,"jb":52.1741370786517,"ff":110.16456426650427},{"kb":21.048498314606718,"jb":52.174099438202255,"ff":110.16456426650427},{"kb":21.04866539325849,"jb":52.17406179775282,"ff":110.16456426650427},{"kb":21.048832471910146,"jb":52.17402415730338,"ff":110.16456426650427},{"kb":21.048999550561803,"jb":52.173986516853944,"ff":110.16456426650427}]'
... and more
Rest of the code:
aobj = JSON.parse(aobj);
function tes_par(nrr,jbb,kkb,hhf)
{
var page = require('webpage').create();
page.viewportSize = { width: 600, height: 480 };
console.log(nrr);
page.open('http://maps.googleapis.com/maps/api/streetview?size=640x480&location='+jbb+','+kkb+'&pitch=-0.760&sensor=false&heading='+hhf, function ()
{
page.render(nrr + '.png');
});
}
for (var i=0;i<aobj.length;i++)
{
tes_par(i,aobj[i].jb,aobj[i].kb,aobj[i].ff);
}
I assume that this is because JS can run one code at a time, so it consumes all resources, but I have no idea how to wait for page.open and page.render and wait if there are more than 1000 calls of these functions.
I also tried to use setTimeout, but again without success:
aobj = JSON.parse(aobj);
function tes_par(nrr,jbb,kkb,hhf)
{
var page = require('webpage').create();
page.viewportSize = { width: 600, height: 480 };
console.log(nrr);
page.open('http://maps.googleapis.com/maps/api/streetview?size=640x480&location='+jbb+','+kkb+'&pitch=-0.760&sensor=false&heading='+hhf, function ()
{
page.render(nrr + '.png');
});
}
function aa_bb(ii)
{
var jj=0;
(ii+500<aobj.length) ? jj=ii+500 : jj=aobj.length;
for (var i=ii;i<jj;i++)
{
tes_par(i,aobj[i].jb,aobj[i].kb,aobj[i].ff);
}
};
aa_bb(1);
setTimeout(function(){aa_bb(501)},120000);