Capture web page screenshot with PhantomJS
I used to be upset when I can not find out how to capture screenshot of web page on server. Now, I find PhantomJS which can help me easily to capture screenshot. This is a script to do:
var system = require('system');
if (system.args == null || system.args.length < 3) {
console.log('Usage: render.js filename URL [width]');
phantom.exit();
}
var filename = 'screenshot.png';
if (system.args.length > 1) {
filename = system.args[1];
}
var url = 'http://codingore.blogspot.com/2016/03/resume-of-tran-inh-thoai.html';
if (system.args.length > 2) {
url = system.args[2];
}
var width = 1024;
if (system.args.length > 3) {
width = parseInt(system.args[3]);
}
var page = require('webpage').create();
page.viewportSize = { width: width, height: 500};
page.open(url);
page.onLoadFinished = function() {
var height = page.evaluate(function() { return document.body.offsetHeight });
var page2 = require('webpage').create();
page2.viewportSize = {
width: width,
height: height
};
page2.open(url, function(status) {
if(status === "success") {
page2.render(filename);
}
phantom.exit();
});
};
Tuesday, March 8, 2016
at
12:27 AM
Blog Archive
-
▼
2016
(29)
-
▼
March
(9)
- Capture web page screenshot with PhantomJS
- Trần Đình Thoại in Osaka, Japan
- Trần Đình Thoại on Sougo Sharyou project
- Trần Đình Thoại on SPACE-Doc project
- All Tags
- Verizon thiết kế lại chào giá FiOS Custom TV
- CEO của Google gặp lãnh đạo chống độc quyền của EU...
- Contact Trần Đình Thoại
- Resume of Trần Đình Thoại
-
▼
March
(9)




