Created
January 24, 2014 23:16
-
-
Save CrowderSoup/8608798 to your computer and use it in GitHub Desktop.
A Phantom.js script to take a screenshot of any website.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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