Skip to content

Instantly share code, notes, and snippets.

@moltar
Created December 6, 2012 18:47
Show Gist options
  • Save moltar/4227007 to your computer and use it in GitHub Desktop.
Save moltar/4227007 to your computer and use it in GitHub Desktop.
screen 10 times
var url = 'http://www.google.com';
var prefix = 'CA';
var totalScreenshots = 10;
var screenshotDelay = 10; // seconds
var i = 0;
function makeScreenshot(url, filename, callback) {
var page = new WebPage();
page.settings.userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0';
page.open(url, function(status) {
var timeoutId = setInterval(function() {
page.render(filename);
clearInterval(timeoutId);
callback.apply();
}, 1000 * screenshotDelay);
});
}
function process() {
if (++i <= totalScreenshots) {
var filename = prefix + '_' + i + '.png';
console.log(filename);
makeScreenshot(url, filename, process);
} else {
phantom.exit();
}
}
process();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment