PhantomJS无效页面渲染

时间:2016-08-05 10:15:04

标签: phantomjs

我在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();
});

我得到截图 enter image description here

虽然Chrome 51向我显示了这样的页面

enter image description here

1 个答案:

答案 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
相关问题