Bruno Andrade
Bruno Andrade

Reputation: 595

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.

Upvotes: 0

Views: 680

Answers (2)

Thomas Walpole
Thomas Walpole

Reputation: 49850

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.

Upvotes: 1

Diogo Rocha
Diogo Rocha

Reputation: 10565

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 
});

Upvotes: 0

Related Questions