I am trying use phantom.js to login in instagram website. My first approach was:
document.querySelector("input[name='username']").value = "Username";
document.querySelector("input[name='password']").value = "Pass";
But this code don't change da DOM.
My second approach:
document.getElementsByClassName("_kp5f7 _qy55y")[0].setAttribute("value", "Username");
document.getElementsByClassName("_kp5f7 _qy55y")[0].value = "Pass";
But when I inspect the network packages fields username and pass are blank.
Instagram login page: https://www.instagram.com/accounts/login/
Update: Please see edit below the answer
I don't really think that
It's probably us not doing good enough of impersonation of a real browser.
A quick search for "instagram login phantomjs" found this neat solution that works: https://github.com/awener/instagram-login-phantomjs/blob/master/phan.js
It uses PhantomJS mechanism of simulating "real" keypresses and clicks.
Here's a copy of the script just in case.
Edit with explanation on how to run the script on Linux
The reason this did not work on Debian/Ubuntu is SSL certificate issues.
There is a verbose mode telling about what PhantomJS is doing, when you run it with --debug=true CLI option. Using that I've found the cause of the problem:
To avoid this type of problems you just have to run Phantomjs with another CLI argument telling it to ignore SSL errors: