用casperjs模拟登录,支持多个账户登录

Posted 向着太阳生

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用casperjs模拟登录,支持多个账户登录相关的知识,希望对你有一定的参考价值。

var casper = require(‘casper‘).create({
    viewportSize:{
        width:1920,
        height:1080
    }
});

var url1 = ‘http://jifen.yuyid.com‘;

var users = [{‘username‘:‘150****656‘,‘password‘:‘xxxxxx‘},{username:‘username‘,password:‘xxxxx‘}];
casper.start();

var autoSingin = function(value,key){
    //打开首页
    casper.thenOpen(url1,function(){
        this.captureSelector(‘jifen.png‘,‘html);
        this.wait(1000); //this.wait方法挡不住当前回调函数下面代码的执行,只能延时下一步要执行的代码,比如下面这个casper.then
        this.click(‘div.go-login‘);
    })

    //填充表单并登录
    casper.then(function(){
        //等待1s后执行这个回调
        this.captureSelector(‘alert.jpg‘,‘html‘);
        this.fill("form#login_form",value,false)

        this.captureSelector(‘filled.jpg‘,‘html‘);

        this.click(‘a.login-btn‘);
        this.wait(3000)
    })

    //点击签到打开窗口
    casper.then(function(){
        this.captureSelector(‘logined.jpg‘,‘html‘);
        this.click(‘#sign-btn‘);
        this.wait(1000);
    })

    //执行签到
    casper.then(function(){
        this.captureSelector(‘click-sigin.png‘,‘html‘);
        this.click(‘.sign-btn-a‘);
        this.wait(1000);
    })

    //签到成功
    casper.then(function(){
        this.capture(‘sigin-success-‘+key+‘.png‘);
        this.click(‘.user>a‘)
    })

}

users.forEach(function(value,key){
    autoSingin(value,key)
})

casper.run();

 

以上是关于用casperjs模拟登录,支持多个账户登录的主要内容,如果未能解决你的问题,请参考以下文章

casperjs模拟登录-jd无验证码签到

ATM机小程序

Python__模拟实现一个ATM+购物商城程序

使用 casperjs/phantomjs 登录到 Amazon Developer 网页

使用 casperJS 登录网站

atm