[ 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.