Casperjs Google登录不起作用 [英] Casperjs Google Login Not working

查看:92
本文介绍了Casperjs Google登录不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用一些代码来访问我的Google财务投资组合,但是问题是我需要使用我的Google帐户登录。所以我做到了:

I having been working on some code to access my google finance portfolio, but the problem is I need to sign in with my google account. So i have made this:

var casper = require('casper').create();
casper.start('https://accounts.google.com/Login?hl=EN', function() {
  this.evaluate(function(username, password) {
      this.echo(this.getTitle());
      document.querySelector('input#Email').value = username;
      document.querySelector('#next').click();
      document.querySelector('input#Passwd').value = password;
      document.querySelector('#signIn').click();
  }, 'GOOGLE EMAIL', 'PASSWORD');
});

casper.then(function() {
    this.echo(this.getHTML()); // => 'The text included in the <h1 id=foobar>'

    casper.thenOpen('https://www.google.com/finance/portfolio?action=view&pid=1&ei=pBrbVoDhM4iFjAGB-bKIAg', function() {
        this.echo(this.getHTML());
        this.echo(this.getTitle());
    });

});

casper.run();

哪个没有登录我!

推荐答案

在我的原始代码中,我从google页面上选择了错误的输入框,相反,它看起来应该像这样:

In my original code I was selecting the wrong input boxes from the google page, instead it should look like this:

var casper = require('casper').create();
casper.start("https://accounts.google.com/Login?hl=EN", function() {
  console.log("page loaded...");
  //console.log(this.getHTML());
  //document.querySelector('#Email').value = "kpfromer@gmail.com";
  //document.querySelector('#next').click();

  this.fillSelectors('form#gaia_loginform', {
    'input[name="Email"]': 'EMAIL',
  }); //Fills the email box with email
  this.click("#next"); //Fills the email box with email


  this.wait(500, function() { //Wait for next page to load
    console.log("Inside WAIT...");

    this.waitForSelector("#Passwd", //Wait for password box
      function success() {
        console.log("SUCCESS...");
        this.fillSelectors('form#gaia_loginform', {
          'input[name="Passwd"]': 'PASSWORD',
        }); //Fill password box with PASSWORD
        this.click("#signIn"); //Click sign in button
        this.wait(500, function() {}); //Wait for it fully sigin
      },
      function fail() {
        console.log("FAIL...");
      }

    );

  });
});
casper.run();

等待的原因是页面完全加载需要一点时间,并且交换到其他页面。

The reason why there are waits is that it takes a little bit for the page to fully load, and swap to other pages.

这篇关于Casperjs Google登录不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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