简体   繁体   English

为什么Phantomjs无法在该站点上使用?

[英]Why does Phantomjs not work with this site?

I'm new to phantomjs and I'm testing with version 2.5.0-development . 我是phantomjs的新手,正在使用2.5.0-development版本进行测试。 I used the script screen.js it works well with http://phantomjs.org and https://google.com but does not work with https://globo.com and https://uol.com.br I can not understand what I do wrong no error appears. 我使用了脚本screen.js它可以与http://phantomjs.orghttps://google.com一起很好地工作,但不能与https://globo.comhttps://uol.com.br一起工作不明白我在做什么错,没有错误出现。

screen.js screen.js

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

Edit: I tried the old version 2.1.1 and it worked. 编辑:我尝试使用旧版本2.1.1,并且可以正常工作。 The problem seems to be the version. 问题似乎是版本。

As mentioned on the phantomjs page - http://phantomjs.org/ - PhantomJS development was stopped, and it's pretty much obsolete at this point in time. 如phantomjs页面( http://phantomjs.org/)所述-PhantomJS开发已停止,并且在这一点上已经过时了。 PhantomJS is basically equivalent to a 6-7 year old browser, doesn't support a lot of current JS/CSS (let, const, flexbox, grid layout, etc), and has the nasty habit of not raising errors when unsupported JS features (like let or const ) are used in an asset of the page and instead just ignoring those JS files. PhantomJS基本上等效于6-7年的浏览器,不支持许多当前的JS / CSS(let,const,flexbox,网格布局等),并且有讨厌的习惯,即在不受支持的JS功能时不引发错误(例如letconst )用于页面的资产中,而只是忽略那些JS文件。 You're going to be much better off switching to something more modern like headless Chrome. 切换到更现代的产品(如无头Chrome),您会变得更好。

I think you must need to wait a bit before page loads. 我认为您必须在页面加载之前稍等片刻。 Try adding a set timeout, for example: 尝试添加设置超时,例如:

var page = require('webpage').create();
page.open('https://www.globo.com', function() {
  setTimeout(function(){
     page.render('globo.png');
     phantom.exit();
  }, 5000); // Change timeout as required to allow sufficient time 
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM