標籤:als select alert jpg 回調 代碼 填充 表單 sel
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類比登入,支援多個賬戶登入