V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
fenglangjuxu
V2EX  ›  JavaScript

v2ex 自动领取积分( casperjs)

  •  
  •   fenglangjuxu · 2017-03-29 15:57:07 +08:00 · 2188 次点击
    这是一个创建于 2556 天前的主题,其中的信息可能已经有所发展或是发生改变。

    ##我看这有用 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();
    	}
    }
    );
    
    
    
    2 条回复    2017-03-29 16:20:32 +08:00
    GjriFeu
        1
    GjriFeu  
       2017-03-29 16:01:30 +08:00
    马上加工能,以后领取都要验证码。
    yuxuan
        2
    yuxuan  
       2017-03-29 16:20:32 +08:00
    同楼主也是看了之前的 Python 写了一个 https://github.com/yuxuangezhu/library/blob/master/v2ex_sign.js 登陆字段是有时效的 每次都不一样
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2733 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 00:23 · PVG 08:23 · LAX 17:23 · JFK 20:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.