1

[ phantomjs -v 1.9.7 ] with NightmareJS: https://github.com/segmentio/nightmare

Having set the options as best as I can see via that one sample that uses the timeout option:

new Nightmare({ignoreSslErrors : 'true', sslProtocol : 'tlsv1'})

also tried

new Nightmare({ignoreSslErrors : true, sslProtocol : 'tlsv1'})

It won't open the the https page.

If I use phantomjs directly to hit the same page it works fine:

phantomjs --ignore-ssl-errors=true --ssl-protocol=tlsv1 testBot.js

Page title is Login

*** testBot.js

var page = require('webpage').create();
var url = 'https://www.some-https-site/login/';
page.onConsoleMessage = function(msg) {
    console.log('Page title is ' + msg);
};
page.open(url, function(status) {
    page.evaluate(function() {
        console.log(document.title);
    });
    phantom.exit();
});

This code is quite messy, but it works perfectly when I switch the site back to HTTP instead of HTTPS.

// Main nightmare call
// Code is quite messy, i know.
new Nightmare({ignoreSslErrors : 'true', sslProtocol : 'tlsv1'})
    .useragent('chrome')
    .use(openpage())
    .evaluate(function() {
        return document.title;
    },function(title) {
        // console.info('FALSE = not logged in');
        console.info('title : ' + title);
        if (title === 'Login'){
            console.info('false');
            loginCheckBit = false;
        }else if (title === 'Print Invoice'){
            loginCheckBit = true;
            console.info('true');
        }else{
            console.info('#########################################');
            console.info(' NEED TO TROUBLESHOOT scraper looks lost');
            console.info('#########################################');
        }

    })
    .run(function(err, nightmare){
        if (err){
            console.info('err : ' + err);
        }
        if (!loginCheckBit){
            new Nightmare({ignoreSslErrors : 'true', sslProtocol : 'tlsv1'})
                .use(login(user))
                .use(screenshot())
                .evaluate(function() {
                    return document.title;
                },function(title) {
                    console.info('#################');
                    console.info('title : ' + title);
                    makePDF();
                })
                .run(function(err, nightmare){
                    if (err){
                        console.info('err : ' + err);
                    }
                });

        }else{
            new Nightmare({ignoreSslErrors : 'true', sslProtocol : 'tlsv1'})
                .use(openpage())
                .use(screenshot())
                .evaluate(function() {
                    return document.title;
                },function(title) {
                    console.info('################');
                    console.info('inside 2nd eval');
                    console.info('title : ' + title);
                    makePDF();
                })
                .run(function(err, nightmare){
                    if (err){
                        console.info('err : ' + err);
                    }
                });

        }

    });

function openpage(user){
    console.info('============ BOT URL CALL =============');
    console.info(rootURL + '/account/invoices/'+req.params.id+'/printerFriendly/');
    console.info('====================================');
    return function(nightmare){
        nightmare
            .goto(rootURL + '/account/invoices/'+req.params.id+'/printerFriendly/')
            .wait();
    };
}
function login(user){
    return function(nightmare){
        nightmare
            .goto(rootURL + '/account/invoices/'+req.params.id+'/printerFriendly/')
            .type("input[name='username']", user.name)
            .type("input[name='password']", user.pass)
            .click('.btn-login')
            .wait();
    };
}

I know that the HTTPS has failed when it calls the 'login' function and it cant find the input boxes :

            .type("input[name='username']", user.name)
            .type("input[name='password']", user.pass)

Nightmare will return an error for the input boxes and the title of the page is null. It should either be: "login" or 'Print Invoice' depending on if the 'bot' is logged in or not.

The following thread put me in the right direction regarding 'tlsv1' : PhantomJS failing to open HTTPS site but I just can't get it working within Nightmare.

Community
  • 1
  • 1
Brendon
  • 11
  • 5
  • Updated. I know the rest of the code is quite messy. Was a bit embarrassing, took a while to get it working the first time around (HTTP), that when it did, i didnt want to touch it again! ;) hence I only pasted what I thought was needed. – Brendon Jan 29 '15 at 14:50

1 Answers1

0

Ok, so my host had provisioned me on Ubuntu 12.04, just as a general upgrade I asked them to reprovision Ubuntu 14.04. I ran my install/deploy scripts. So the exact same codebase. It is WORKING now!

My scripts installed the exact same version of PhantomJS and NightmareJS in the exact same way. So I really do not now what the issue was. But the code I have above is correct and its working, incase anybody else is trying something similar and have doubts.

Brendon
  • 11
  • 5