简体   繁体   中英

Why does Phantomjs not work with this site?

I'm new to phantomjs and I'm testing with version 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

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. 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 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. You're going to be much better off switching to something more modern like headless 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 
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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