Zoomzoom
Zoomzoom

Reputation: 189

PhantomJS Url fail to load for unknown reason

Here is the URL I'm trying to load with PhantomJS : http://shop.karinelecchi.fr/collections/jupes-robes/products/jalousie

Here is my code :

var fs      = require("fs");
var system  = require("system");

var page = require('webpage').create();
page.settings.userAgent = "Mozilla/5.0 (compatible; Googlebot/2.1;+http://www,google,com/bot.html)";
page.settings.loadImages = false;
var url = "http://shop.karinelecchi.fr/collections/jupes-robes/products/jalousie";

page.onConsoleMessage = function(msg) {
 console.log(msg);
};
page.open(url, function (status) {
if (status !== 'success') {
    console.log('Unable to load the address!');
    phantom.exit();
} else {
    console.log('Yiha! load the address!');
    phantom.exit(); 
}
});

My output : "Unable to load the address"

Any guesses? Thx

Upvotes: 0

Views: 1879

Answers (1)

Here you have a website that explains how to track down url load fails: https://newspaint.wordpress.com/2013/04/25/getting-to-the-bottom-of-why-a-phantomjs-page-load-fails/

Just in case the site goes down, I'm going to copy here important details on how to track down those problems:

Just before calling page.open() add the following code:

page.onResourceError = function(resourceError) {
    page.reason = resourceError.errorString;
    page.reason_url = resourceError.url;
};

Now you can print out the reason for a problem in your page.open() callback, e.g.:

page.open(
    "http://www.nosuchdomain/",
    function (status) {
        if ( status !== 'success' ) {
            console.log(
                "Error opening url \"" + page.reason_url
                + "\": " + page.reason
            );
            phantom.exit( 1 );
        } else {
            console.log( "Successful page open!" );
            phantom.exit( 0 );
        }
    }
);

This script outputs the following:

Error opening url "http://www.nosuchdomain/": Host www.nosuchdomain not found

Remember that page also has an onError event where you can get more info.

Upvotes: 2

Related Questions