Wednesday, September 16, 2015

Phantomjs Failing to Open Https Site - SSL Handshake Failed

Phantomjs Failing to Open Https Site - SSL Handshake Failed

I am using Phantom JS for scrapping sites. During scrapping I faced some issue with Phantom JS (Webpage module). Phantom JS site has very less details about Web Page module.

So, here is some more information about Phantom JS Web Page module : 

How to Use Web Page Module using Phantom JS

Web Page module has been used mostly for scrapping the data from a website.

    var webPage = require('webpage'); 
    var page = webPage.create();
    page.open('url', function(status){
    })

How to debug Web Page Module?

When you use web page module and if any issue come then web page module do not show any error it simply give status fail.

But you can do couple of thing for understanding the issue. 
Before the page.load you use following code for getting the error :
         
          page.onResourceError = function(err) { 
          page.reason = err.errorString;
page.cause_url = err.url; 
           } 


Now you can print the reason inside page.open.

page.open('url', function(status) {
         if ( status == 'fail' ) {
              console.log(page.reason);
              console.log(page.cause_url);
         }
})

How to solve "SSL Handshake Failed" issue?


If you are getting "SSL Handshake Failed" issue then you should run the Phantom JS script with following command. One of them should solve your issue :
  1. phantomjs --ignore-ssl-errors=true test.js
  2. phantomjs --ignore-ssl-errors=true --ssl-protocol=tlsv1 test.js

Enjoy :)

No comments:

Post a Comment