I am trying to automate the process of downloading many webpage screenshots. All screenshots are on the same page, but different data come up based on the querystring parameter.
my code:
var page = require('webpage').create();
//How far the page extends in the image
page.viewportSize = { width: 1024, height: 2500 };
//size of the actual clip in the viewer (extra black space below image)
page.clipRect = { top: 0, left: 0, width: 1024, height: 4500 };
console.log("configured");
for(var i = 1; i < 5; i++){
page.open('http://testsite.com/view?id=' + i, function(status) {
console.log("Status: " + status);
if(status === "success") {
//save image of page as this
page.render(i + '.png');
}
phantom.exit();
});
}
This works without the for loop and just setting i to a random number. I have a feeling it has to do with the callback function and/or the placement of phantom.exit(). I have tried many variations and cannot get it to loop. I have also tried adding a custom synchronous delay function, but am not sure where this might be called. What would be the best way to automate this...time and resources are not an intensive issue, as this just needs to be run once to dump all the pictures to a file.