1

I have a phantomJS script

var page = require('webpage').create();
var system = require('system');

page.settings.userAgent = 'SpecialAgent';

var i = 1;
var url = 'http://www.google.cz/?test=' + i;
console.log( "url='" + url + "'" );
page.open(url, function (status) {
    if (status !== 'success') {
        console.log( 'Unable to access network' );
    } else {
        console.log( 'Opened ok' );
        phantom.exit();
    }
});

which works fine, but when I wrap the page.open in for loop as

var page = require('webpage').create();
var system = require('system');

page.settings.userAgent = 'SpecialAgent';

//var i = 1;
for ( var i = 1; i <= 2; ++i ) {
    var url = 'http://www.google.cz/?test=' + i;
    console.log( "url='" + url + "'" );
    page.open(url, function (status) {
        if (status !== 'success') {
            console.log( 'Unable to access network' );
        } else {
            console.log( 'Opened ok' );
            phantom.exit();
        }
    });
}

I'm getting

Unable to access network

I think it is because it is executed in parallel. Am I correct? (phantom.exit() is in wrong place probably) How can I wait for processing page.open and then execute next iteration?

Betlista
  • 10,327
  • 13
  • 69
  • 110
  • Yes, this is very likely due to trying to `open` after exit. See if [this](http://stackoverflow.com/a/26681840) or [this](http://stackoverflow.com/a/26827083) approach help. This is basically the same approach, but with slightly different tools. Interestingly the two OP didn't even bother to respond. – Artjom B. Nov 14 '14 at 16:35
  • No, it's not about the `exit()`, when I commented this command still the same error. – Betlista Nov 14 '14 at 17:28

1 Answers1

0

The problem is that PhantomJS version < 1.9.8 uses SSLv3 by default, but because of the POODLE vulnerability most webservers have disabled SSLv3 support, so you need to explicitly add the --ssl-protocol=tlsv1 (or) --ssl-protocol=any commandline option.

When you run your script using phantomjs, add the following command line options

phantomjs --ssl-protocol=any yourscript.js

If you're still getting an error it may be due to SSL certificate errors, using --ignore-ssl-errors=yes option should proceed to load the page as it will ignore all ssl errors, including malicious ones.

phantomjs --ssl-protocol=any --ignore-ssl-errors=yes yourscript.js