Last active
August 29, 2015 14:14
-
-
Save stekhn/601e35a71f1055887cb3 to your computer and use it in GitHub Desktop.
Take a screenshot from a website using PhantomJS
This file contains hidden or 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'), | |
args = system.args, | |
siteName; | |
function takeScreenshot() { | |
if (args.length === 1) { | |
console.log('Please specify a URL to screenshot.'); | |
phantom.exit(); | |
} else { | |
siteName = args[1].match(/^https?\:\/\/([^\/:?#]+)(?:[\/:?#]|$)/i)[1]; | |
timestamp = getTimestamp(); | |
page.open('http://sueddeutsche.de', function(status) { | |
console.log('Trying to take screenshot from ' + siteName); | |
if(status === 'success') { | |
page.render(sitename + '.png'); | |
console.log('Screenshot taken.'); | |
phantom.exit(); | |
} else { | |
console.log('Could not open page. Status: ' + status); | |
phantom.exit(); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment