我在Windows 7 x64上使用phantomjs来制作我的页面截图。我的代码是
var webPage = require('webpage');
var page = webPage.create();
page.viewportSize = { width: 1920, height: 1080 };
page.open("http://localhost/index.html", function start(status) {
page.render('screeshot.png', {format: 'png', quality: '100'});
phantom.exit();
});
虽然Chrome 51向我显示了这样的页面
答案 0 :(得分:0)
添加延迟,可能是phantomjs没有完全加载网站
var webPage = require('webpage');
var page = webPage.create();
page.viewportSize = { width: 1920, height: 1080 };
page.open("http://localhost/index.html", function start(status) {
setTimeout(function() {
page.render('screeshot.png', {format: 'png', quality: '100'});
phantom.exit();
}, 5000);
});
或使用命令行尝试此脚本(https://github.com/ariya/phantomjs/blob/master/examples/rasterize.js):
phantomjs rasterize.js http://localhost/index.html /yourFolder 1920px