PhantomJS page.open freezes

拈花ヽ惹草 提交于 2019-12-11 03:13:24

问题


I am trying to open a website using PhantomJS using the Capture example

var page = require('webpage').create();
page.open('http://github.com/', function() {
  page.render('github.png');
  phantom.exit();
});

The code works fine on my local machine, using Ubuntu 14.04. But when I run the code on a virtual server, the callback is never called and the script does not exit. The server and my local machine are running the exact same setup. I tried it on 2 different servers on virtualised with VMWare and one with Virtuozzo.

It does not seem to be a network error as all requests are successful.


回答1:


Actually the UserAgent caused all the trouble. @artjom-b pointed me to this Question Taking reliable screenshots of websites? Phantomjs and Casperjs both return empty screen shots on some websites. The Only difference is that for me the image file was never created.

So setting the UserAgent with

page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36';

actually solved the problem.



来源:https://stackoverflow.com/questions/26609450/phantomjs-page-open-freezes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!