Last active
August 29, 2015 13:57
-
-
Save mfyz/9862163 to your computer and use it in GitHub Desktop.
Take snapshot of a webpage with 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
// run this with phantomjs | |
//create new webpage object | |
//var page = new WebPage(); | |
var page = require('webpage').create(); | |
//load the page | |
page.open('http://mfyz.com', function (status) { | |
//fire callback to take screenshot after load complete | |
page.render('mfyz.png'); | |
//finish | |
phantom.exit(); | |
}); |
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
// run this script with node using phantom module | |
var page = require('webpage').create(); | |
page.open('http://moonit.com', function() { | |
var pageHeight = page.evaluate(function() { | |
return document.body.offsetHeight; | |
}); | |
page.viewportSize = { width: 1200, height: pageHeight + 50 }; | |
page.clipRect = { width: 1200, height: pageHeight + 50 }; | |
// Take screenshot of the page. | |
page.paperSize = 'Letter'; | |
window.setTimeout(function () { | |
page.render('screenshot.png'); | |
phantom.exit(); | |
}, 200); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment