我试图用PhantomJS加载页面并将其保存为.png。但是,创建的png看起来并不像原来的那样,并且缺少大部分正文。在线搜索中,大部分类似的问题都是因为没有足够长的时间来加载页面。但是,这还没有解决我的问题。这是我正在运行:PhantomJS未加载动态内容
var page = require('webpage').create();
var websiteAddress = 'http://poe.ninja/standard/currency';
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36';
//viewportSize being the actual size of the headless browser
page.viewportSize = { width: 1920, height: 1080 };
//the clipRect is the portion of the page you are taking a screenshot of
page.clipRect = { top: 0, left: 0, width: 1920, height: 1080 };
page.open(websiteAddress, function (status) {
setTimeout(function(){
page.render('output.png');
phantom.exit();
}, 5000); // 5 sec should be enough
});
我做错了什么或者这是一个在PhantomJS中的错误?
下面是它应该是什么样子和图像它实际上是这样的:
添加[page.onError](http://phantomjs.org/api/webpage/handler /on-error.html)回调来检查是否有任何错误。 – Vaviloff