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();
时间: 2024-10-08 20:47:51