javascript - Troubleshoot PhantomJS code to sign in to Instagram -


i've written phantomjs script automate signing in instagram. can fill in form fields , press submit button, gets redirected logon screen following message:

your username or password incorrect.

i 100% positive credentials correct, , tried multiple instagram accounts.

i'm running script on mac terminal:

$ phantomjs --ssl-protocol=any --cookies-file=cookies.txt script.js username password 

note --ssl-protocol=any option. without phantomjs can't open login page because of https. see this question.

here's code. based off this tutorial, , updated code account recent changes in source code of instagram's login page.

var system = require('system'); var username = system.args[1]; var password = system.args[2]; var page = require('webpage').create();  page.open('https://instagram.com/accounts/login/',     function (status) {         if (status === "success") {             page.evaluate(function (uid, pwd) {                 var username_field = document.getelementbyid('lffieldinputusername');                 username_field.value = uid;                 var password_field = document.getelementbyid('lffieldinputpassword');                 password_field.value = pwd;             }, username, password);              var point = page.evaluate(function () {                 var element = document.getelementsbytagname('button')[0];                 var rect = element.getboundingclientrect();                 return {                     x: rect.left + math.floor(rect.width / 2),                     y: rect.top + math.floor(rect.height / 2)                 };             });             page.render('before-submit.png');             page.sendevent('click', point.x, point.y);         }         settimeout(function () {             var error = page.evaluate(function () {                 var element = document.getelementbyid('erroralert');                 var error_message = false;                 if (element !== null) {                     error_message = element.innertext.trim();                 }                 return error_message;             });              page.render('after-submit.png');             if (!error) {                 console.log('login successful: ' + page.url);             } else {                 console.log('login failed: ' + error);             }              phantom.exit(0);         }, 5000);     } ); 

and here's i've tried far:

  1. setting cookies. besides adding --cookies-file=cookies.txt command line option, i've tried phantom.addcookie in code. didn't seem make difference.
  2. explicitly sending auth headers. see this question.
  3. changing timezone. not sure if makes sense. see this question.

apparently phantomjs has issues ssl. should give using purpose?

i think problem instagram login reactjs. when set value of text field, react doesn't change state. means login , password sending empty when submit form.

i didn't try, think should fill text inputs keypress event, because internal component (react) state changing when inputs text changing. setting value in way not trigger change event.


Comments