1

这是我用来登录 Quora 的代码:

var casper = require('casper').create({ 
    verbose: true, 
    logLevel: 'debug',
    pageSettings: {
         loadImages:  false,         // The WebPage instance used by Casper will
         loadPlugins: false,         // use these settings
         userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4'
    }
});

casper.start('http://www.quora.com', function()
    {
        this.echo("page loaded");
        this.test.assertExists('form.inline_login_form', 'form is found');
        this.fill('form.inline_login_form',{email:'XXXXX',password:'XXXXX'},true);

    }
);


casper.then(function(){
   this.echo("Page Title " + document.title);
});

casper.run();

这是我看到的输出:

[info] [phantom] Starting...
[info] [phantom] Running suite: 3 steps
[debug] [phantom] opening url: http://www.quora.com/, HTTP GET
[debug] [phantom] Navigation requested: url=http://www.quora.com/, type=Other, lock=true, isMainFrame=true
[debug] [phantom] Navigation requested: url=https://www.quora.com/, type=Other, lock=true, isMainFrame=true
[debug] [phantom] url changed to "https://www.quora.com/"
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step 2/3 https://www.quora.com/ (HTTP 302)
page loaded
PASS form is found
[info] [remote] attempting to fetch form element from selector: 'form.inline_login_form'
[debug] [remote] Set "email" field value to XXXXXXX
[debug] [remote] Set "password" field value to ********
[info] [remote] submitting form to unknown, HTTP POST
[info] [phantom] Step 2/3: done in 2517ms.
[debug] [phantom] Navigation requested: url=about:blank, type=Other, lock=true, isMainFrame=false
[debug] [phantom] Navigation requested: url=about:blank, type=Other, lock=true, isMainFrame=false
[debug] [phantom] Navigation requested: url=https://www.quora.com/, type=FormSubmitted, lock=true, isMainFrame=true
[debug] [phantom] Navigation requested: url=https://s-static.ak.facebook.com/connect/xd_arbiter.php?version=25#channel=f2c1b2e7dc&origin=https://www.quora.com&channel_path=/?fb_xd_fragment#xd_sig=f3e9a78ef8&, type=Other, lock=true, isMainFrame=false
[debug] [phantom] Navigation requested: url=https://www.facebook.com/plugins/facepile.php?size=small&max_rows=1&width=400&color_scheme=dark&app_id=136609459636&locale=en_US&sdk=joey&channel=https://s-static.ak.facebook.com/connect/xd_arbiter.php?version=25#cb=f2850df0f8&origin=https%3A%2F%2Fwww.quora.com%2Ff2c1b2e7dc&domain=www.quora.com&relation=parent.parent, type=Other, lock=true, isMainFrame=false
[info] [remote] Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL https://www.facebook.com/plugins/facepile.php?size=small&max_rows=1&width=400&color_scheme=dark&app_id=136609459636&locale=en_US&sdk=joey&channel=https%3A%2F%2Fs-static.ak.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D25%23cb%3Df2850df0f8%26origin%3Dhttps%253A%252F%252Fwww.quora.com%252Ff2c1b2e7dc%26domain%3Dwww.quora.com%26relation%3Dparent.parent. Domains, protocols and ports must match.

[debug] [phantom] url changed to "https://www.quora.com/"
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step 3/3 https://www.quora.com/ (HTTP 302)
Page Title 
[info] [phantom] Step 3/3: done in 5876ms.
[info] [phantom] Done 3 steps in 5975ms

我期待它登录并显示标题。像'Home-Quora..'这样的东西为什么没有发生?

4

1 回答 1

0

您是否尝试使用您的 Facebook 密码登录?如果是这样,由于弹出窗口被阻止,通过 Facebook 登录会出现问题。

于 2013-07-17T20:21:59.057 回答