无法使用CasperJS提交表单 - 换句话说无法登录

Vla*_*kov 2 javascript tumblr node.js casperjs

我试图登录到的tumblr使用方法CasperJS start,fillwaitForUrl无法做到这一点.在我看来,表单未提交,因为waitForUr每次都过期超时.

终端响应:

我正在使用的代码是这样的:

/*jslint browser: true, regexp: true */
// global casper, require 

var LOGIN_URL, LOGIN_USERNAME, LOGIN_PASSWORD, casper;

casper = require('casper').create({
    waitTimeout: 20000,
    viewportSize: {
        width: 1024,
        height: 768
    },
    verbose: true,
    logLevel: 'debug',
    userAgent: 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'
});

if (!casper.cli.has('username') && !casper.cli.has('password')) {
    casper.echo('Usage: $ casperjs sfdclogin.casper.js --username=USERNAME --password=PASSWORD').exit(-1);
}

LOGIN_URL = 'https://tumblr.com/login';

LOGIN_USERNAME = casper.cli.get('username');
LOGIN_PASSWORD = casper.cli.get('password');

phantom.cookiesEnabled = true;

casper
    .start(LOGIN_URL, function () {
        // 'use strict';

        this.log('Logging in', 'debug');
        /*
        this.fillSelectors('#signup_form_form', {
            '#signup_email': LOGIN_USERNAME,
            '#signup_password': LOGIN_PASSWORD
        }, true);
        */

        this.fill('#signup_form_form', {
            '#user[email]': LOGIN_USERNAME,
            '#user[password]': LOGIN_PASSWORD
        }, true);
    })

    .waitForUrl('http://tumblr.com/dashboard', function () {
        // 'use strict';

        this.echo('We\'re logged in.');
    })

    .run();
Run Code Online (Sandbox Code Playgroud)

此外,我正在使用此脚本使用正确的用户名和密码.

hex*_*xid 6

尝试使用以下代替当前casper.fill().这是因为CasperJS' fill()搜索元素的name属性.

this.fill('#signup_form', {
    'user[email]': LOGIN_USERNAME,
    'user[password]': LOGIN_PASSWORD
}, true);
Run Code Online (Sandbox Code Playgroud)

如果要继续使用id作为选择器,可以使用此方法.

this.fillSelectors('#signup_form', {
    '#signup_email': LOGIN_USERNAME,
    '#signup_password': LOGIN_PASSWORD
}, true);
Run Code Online (Sandbox Code Playgroud)