我在SO中使用了几十个答案中的不同变体和建议,但似乎没有什么能帮助我解决这个问题,我将在下面解释。
有一些网站,其中phantomjs截图看起来很糟糕,内容是在页面加载完成后通过javascript加载的,因此屏幕截图看起来缺少内容。我还在项目的Github问题页面上发布了一个问题,但答案没有帮助。
https://github.com/ariya/phantomjs/issues/14341
上下文中的一个网站是https://angular.io/
我尝试在使用setTimeout延迟一段时间后在Page Load Finished上截屏,并尝试实现waitFor方法,如下所述:Implementing waitFor functionality with phantomjs-node
任何比网站附带的屏幕截图更好的东西都会被接受作为答案。为了测试我正在谈论的内容,可以使用以下代码:https://github.com/crackjack/bulk-shot/
此代码有效,但只提供了一个部分,如预期的那样。如果你进一步增加高度,屏幕截图并不好。
var webPage = require('webpage');
var page = webPage.create();
page.viewportSize = {
width: 1024,
height: 960
};
// Portion of the page to take a screenshot of
page.clipRect = {
top: 0,
left: 0,
width: 1024,
height: 960
};
page.open('https://angular.io/', function (status) {
window.setTimeout(function(){
page.render('angular.jpg');
phantom.exit();
}, 1000);
});