Skip to content

Instantly share code, notes, and snippets.

@0xjams
Last active December 2, 2015 17:09
Show Gist options
  • Save 0xjams/50ce6043e36886fa7da0 to your computer and use it in GitHub Desktop.
Save 0xjams/50ce6043e36886fa7da0 to your computer and use it in GitHub Desktop.
A script to use Phantomjs to get screenshots of an array of urls.
var urls=["https://reddit.com","https://facebook.com"];
var page = require('webpage').create();
page.urls=urls;
console.log("Working with " + page.urls.length + " urls");
page.currentIndex=0;
page.nextScreenshot=function(){
console.log("Getting screenshot of: " + page.urls[page.currentIndex]);
page.open(page.urls[page.currentIndex], function(status) {
console.log("Status: " + status);
if(status === "success") {
name=page.urls[page.currentIndex];
name=name.replace("://","_");
name=name.replace(/\//g,"_");
console.log("Name: " + name);
page.render( name + '.png');
page.currentIndex++;
console.log("Next index " + page.currentIndex);
if(page.currentIndex<page.urls.length)
{
console.log("Going to next index " + page.currentIndex);
page.nextScreenshot();
}
else
{
console.log("Finishing");
phantom.exit();
}
}
else
{
console.log("Error with url "+ page.urls[page.currentIndex]);
}
});
}
page.nextScreenshot();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment