Skip to content

Instantly share code, notes, and snippets.

@CrowderSoup
Created January 24, 2014 23:16
Show Gist options
  • Save CrowderSoup/8608798 to your computer and use it in GitHub Desktop.
Save CrowderSoup/8608798 to your computer and use it in GitHub Desktop.
A Phantom.js script to take a screenshot of any website.
var page = require('webpage').create(),
system = require('system'),
t, address;
if (system.args.length === 1) {
console.log('Usage: screenshot.js <some URL>');
phantom.exit();
}
address = system.args[1];
page.viewportSize = { height: 1280, width: 1920 };
page.clipRect = { top: 0, left: 0, width: 1920, height: 1280 };
page.open(address, function(status){
window.setTimeout(function(){
var docTitle = page.evaluate(function(){
return document.title.replace(/[|&;$%@"<>()+,]/g, "");
});
var imgName = docTitle.replace(/ /g,'') + ".png";
if(status !== 'success') {
console.log("Something went wrong.");
phantom.exit();
}
page.render(imgName);
phantom.exit();
}, 500);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment