解决PhantomJS code可以登录到Instagram的 [英] Troubleshoot PhantomJS code to sign in to Instagram

查看:227
本文介绍了解决PhantomJS code可以登录到Instagram的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了这个PhantomJS脚本来自动登录到Instagram的。它可以成功地填写表单字段和preSS提交按钮,但它总是得到以下消息重定向到登录屏幕:

I've written this PhantomJS script to automate signing in to Instagram. It can successfully fill in the form fields and press the submit button, but it always gets redirected back to the logon screen with the following message:

您的用户名或密码不正确。

Your username or password was incorrect.

我是100%正面的凭据是正确的,我拥有多个账户的Instagram尝试了。

I am 100% positive that the credentials are correct, and I tried it with multiple Instagram accounts.

我是从终端运行脚本在Mac上:

I'm running the script on a Mac from terminal:

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

请注意在 - SSL协议=任意选项。没有它PhantomJS甚至无法打开,因为HTTPS的登录页面。请参见这个问题

Note the --ssl-protocol=any option. Without it PhantomJS can't even open the login page because of HTTPS. See this question.

这里的code。我基于它关闭<一个href=\"https://www.safaribooksonline.com/library/view/getting-started-with/9781782164227/ch02s04.html\">this教程,并更新了code占最近的Instagram的登录页面的源代码code中的变化。

Here's the code. I based it off this tutorial, and updated the code to account for the recent changes in the 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 what I've tried so far:


  1. 设置的cookie。除了增加了 - 饼干文件= cookie.txt的命令行选项,我也试着 phantom.addCookie 在code。似乎没有任何区别。

  2. 明确发送身份验证头。请参见这个问题

  3. 更改时区。不知道这是有道理的。请参见这个问题

  1. Setting cookies. Besides adding the --cookies-file=cookies.txt command line option, I've also tried phantom.addCookie in the code. Didn't seem to make any difference.
  2. Explicitly sending auth headers. See this question.
  3. Changing the timezone. Not sure if this makes sense. See this question.

显然PhantomJS与SSL一些问题。我是不是应该放弃使用它用于此目的?

Apparently PhantomJS has some issues with SSL. Should I just give up using it for this purpose?

推荐答案

我觉得跟Instagram的登录,它的问题是ReactJs。当您设置文本字段的值,反应不改变状态。这意味着,登录名和密码发送空当您提交表单。

I think that problem with Instagram login is ReactJs. When You set value of text field, React doesn't change state. It means that login and password sending empty when you submit form.

我没有尝试,但我认为你应该填写与关键preSS事件文本输入,因为内部组件(阵营)状态只有当改变输入的文本改变。在你的方式设定值将不会触发更改事件。

I didn't try, but I think you should fill text inputs with keypress event, because internal component (React) state only changing when inputs text changing. Setting value in you way will not trigger change event.

这篇关于解决PhantomJS code可以登录到Instagram的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆