Update: see edit below answer
I really don't think that
PhantomJS cannot process this page.
Itβs probably not good enough for us to impersonate a real browser.
A quick search of "phramomjs login instagram" found this neat solution that works in : https://github.com/awener/instagram-login-phantomjs/blob/master/phan.js
It uses the PhantomJS engine to simulate "real" keystrokes and clicks.
Here's a copy of the script just in case.
var page = require('webpage').create(); var username = "myusername"; var password = "password"; page.viewportSize = { width: 1024 , height: 600 }; page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36'; page.open('https:/instagram.com/accounts/login/', function() { var ig = page.evaluate(function() { function getCoords(box) { return { x: box.left, y: box.top }; } function getPosition(type, name) { // find fields to fill var input = document.getElementsByTagName(type); for(var i = 0; i < input.length; i++) { if(name && input[i].name == name) return getCoords(input[i].getBoundingClientRect()); else if(!name && input[i].className) return getCoords(input[i].getBoundingClientRect()); // this is for login button } } return { user: getPosition('input', 'username'), pass: getPosition('input', 'password'), login: getPosition('button') }; }); // fill in data and press login page.sendEvent('click',ig.user.x, ig.user.y); page.sendEvent('keypress', username); page.sendEvent('click',ig.pass.x, ig.pass.y); page.sendEvent('keypress', password); page.sendEvent('click', ig.login.x, ig.login.y); // wait for response setTimeout(function() { page.render('/path/to/screenshot.png'); phantom.exit(); }, 5000); });
Edit to explain how to run a script on Linux
The reason this doesn't work on Debian / Ubuntu is because of problems with SSL certificates.
There is a verbose mode that talks about what PhantomJS does when you start it with the --debug = true CLI option. Using this, I found the cause of the problem:
[DEBUG] Network - SSL Error: "The issuer certificate of a locally looked up certificate could not be found" [DEBUG] Network - SSL Error: "The root CA certificate is not trusted for this purpose" [DEBUG] Network - Resource request error: QNetworkReply::NetworkError(SslHandshakeFailedError) ( "SSL handshake failed" ) URL: "https://instagramstatic-a.akamaihd.net/h1/scripts/polyfills/es5-sham.min.js/fc3c22cf2d67.js" ...
To avoid such problems, you just need to start Phantomjs with another CLI argument saying that it ignores SSL errors:
/pth/to/phantomjs --ignore-ssl-errors=true /path/to/script.js