v2ex 自动领取积分( casperjs)

2017-03-29 15:57:07 +08:00
 fenglangjuxu

##我看这有用 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('https://www.v2ex.com/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('https://www.v2ex.com/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();
	}
}
);


2202 次点击
所在节点    JavaScript
2 条回复
GjriFeu
2017-03-29 16:01:30 +08:00
马上加工能,以后领取都要验证码。
yuxuan
2017-03-29 16:20:32 +08:00
同楼主也是看了之前的 Python 写了一个 https://github.com/yuxuangezhu/library/blob/master/v2ex_sign.js 登陆字段是有时效的 每次都不一样

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/351218

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX