javascript - CasperJS not working in login website -
here code, want print out element's value logged in page have, failed. https://mp.weixin.qq.com/cgi-bin/loginpage?t=wxm2-login&lang=zh_cn
page want login.
/** * usage: casperjs test.js 111111@qq.com password * # phantomjs --version * 1.9.7 * # casperjs --version * 1.1.0-beta3 */ var casper = require('casper').create({ loglevel: 'debug', verbose: true, pagesettings: { loadimages: false, // not load images loadplugins: false // not load npapi plugins (flash, silverlight, ...) }, clientscripts: [ './jquery-1.11.1.min.js' ], }); casper.useragent('mozilla/5.0 (windows nt 6.1; rv:29.0) gecko/20100101 firefox/29.0'); // removing default options passed python executable casper.cli.drop("cli"); casper.cli.drop("casper-path"); if (casper.cli.args.length === 0 && object.keys(casper.cli.options).length === 0) { casper.echo("no arg nor option passed").exit(); } var usr = casper.cli.get(0); var passwd = casper.cli.get(1); casper.start().thenopenandevaluate('https://mp.weixin.qq.com/', function() { var f = document.queryselector('form'); f.queryselector('input[id="account"]').value = '111111@qq.com'; f.queryselector('input[id="password"]').value = 'password'; f.submit(); }); casper.then(function() { this.echo('page url ' + this.getcurrenturl()); this.echo('page title ' + this.gettitle()); }); casper.run();
i've tried other login methods, not work, i'm wondering if website has forbids otherwise why not work:
// method 1 login casper.start('https://mp.weixin.qq.com/', function() { this.fillselectors('form#login-form', { 'input[id="account"]': "1111@qq.com", 'input[id="password"]': passwd }, false); this.sendkeys('#account', '1111@qq.com'); this.sendkeys('#password', "1111"); this.click('#login_button'); //this.sendkeys('input[id="account"]', "my_account"); //this.sendkeys('input[id="password"]', "my_password"); //this.click('#login_button'); }); // method 2 login casper.start().thenopen('https://mp.weixin.qq.com/cgi-bin/login?lang=zh_cn', { method: "post", data: { f: 'json', imgcode: '', username: '1111@qq.com', pwd: '00fbd6d3e86be9c1f3cd2e7f22b17505' } }, function() { this.echo("post request has been sent."); this.echo('page url ' + this.getcurrenturl()); this.echo('page title ' + this.gettitle()); });
update phantom.js
npm install -g phantomjs@1.9.9
Comments
Post a Comment