admin管理员组文章数量:1355609
I was doing some research in many websites today and, to avoid looking at them manually, I prepared phantomjs to render them using the solution proposed here. Nothing special. Looping through a website array and rendering all the resulting pages.
What's strange is that there are some websites that are not being properly rendered. Among others, I have this one: /
To simplify, I created another script that only runs this page:
var page = require('webpage').create();
page.viewportSize = { width: 1920, height: 960 };
page.clipRect = { top: 0, left: 0, width: 1920, height: 960 };
page.open('/', function(status) {
page.render("screenshot.png");
phantom.exit();
});
It ends in no screenshot. Tested with any other one, and perfectly working. Did I overlook something?
I was doing some research in many websites today and, to avoid looking at them manually, I prepared phantomjs to render them using the solution proposed here. Nothing special. Looping through a website array and rendering all the resulting pages.
What's strange is that there are some websites that are not being properly rendered. Among others, I have this one: http://www.telegraaf.nl/
To simplify, I created another script that only runs this page:
var page = require('webpage').create();
page.viewportSize = { width: 1920, height: 960 };
page.clipRect = { top: 0, left: 0, width: 1920, height: 960 };
page.open('http://www.telegraaf.nl/', function(status) {
page.render("screenshot.png");
phantom.exit();
});
It ends in no screenshot. Tested with any other one, and perfectly working. Did I overlook something?
Share Improve this question edited May 23, 2017 at 12:26 CommunityBot 11 silver badge asked Nov 12, 2015 at 17:52 Sergi JuanolaSergi Juanola 6,6478 gold badges59 silver badges94 bronze badges1 Answer
Reset to default 8It doesn't render a screenshot, because the page has no <body>
initially and therefore nothing to render. Everything, including the body, is loaded through JavaScript after PhantomJS' onLoadFinished event fires.
You need to wait a little for a full page load. A simple 5 second wait was sufficient for me:
page.open('http://www.telegraaf.nl/', function(status) {
setTimeout(function(){
page.render("screenshot.png");
phantom.exit();
}, 5000);
});
You can of course wait in a more fancy way in order to make it more robust and not to wait too long: phantomjs not waiting for “full” page load
You may need to run PhantomJS with --ignore-ssl-errors=true
(and maybe --ssl-protocol=any
if PhantomJS <1.9.8).
本文标签: javascriptphantomjs doesn39t render a pageStack Overflow
版权声明:本文标题:javascript - phantomjs doesn't render a page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744048709a2582021.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论