
##我看这有用 python 实现的自动登陆然后领取,我就想用 casperjs 实现下,但是卡住了。卡在登陆成功后,点击一个链接到一个新页面。下面是代码,有木有高手,给指导下啊。
var casper = require('casper').create({ verbose: true, logLevel: 'debug' }); casper.options.waitTimeout = 1000; phantom.outputEncoding="UTF-8"; var system = require('system'); //casper.echo(system.args[4]); //phantom.exit(); var passwd = system.args[4]; //var fs = require("fs"); var passwd = 'xxxx';//v2ex passwd var name = "xxxx";//v2ex email //casper.exit(); casper.start('signin'); // ok code wcd casper.then(function(){ this.fillXPath('form[action="/signin"]',{ '//input[@type="text"]': name, '//input[@type="password"]': passwd },false); }); casper.thenClick('input[type="submit"]'); /* casper.thenEvaluate( function getgift(){ document.querySelector('a[href="/mission/daily"]').click(); } ); casper.captureSelector('v2exok.png','a[href="/mission/daily"]'); casper.echo("ok"); */ casper.then(function() { this.echo(this.getTitle()); }); casper.run( function(){ if(casper.exists(".box .inner")){ casper.echo("login ok"); /* casper.thenOpen('mission/daily', function() { //casper.captureSelector('v2exok2222.png','.box'); //casper.click('input[value="领取 X 铜币"]'); casper.echo("end"); }); casper.run(); */ casper.thenEvaluate( function (){ document.querySelector('a[href="/mission/daily"]').click(); } ); //casper.clickLabel('领取今日的登录奖励','a'); casper.capture('1.png'); casper.then(function() { this.wait(5000,function() { this.capture("2.png"); }); }); casper.waitForSelector('input[value="领取 X 铜币"]', function() { casper.echo("here"); casper.capture('3.png'); }, function() { this.die('no re ').exit(); }, 2000); casper.exit(); }else{ casper.echo("login error"); casper.exit(); } } ); 1 GjriFeu 2017-03-29 16:01:30 +08:00 马上加工能,以后领取都要验证码。 |
2 yuxuan 2017-03-29 16:20:32 +08:00 同楼主也是看了之前的 Python 写了一个 https://github.com/yuxuangezhu/library/blob/master/v2ex_sign.js 登陆字段是有时效的 每次都不一样 |