代码:
Date.prototype.Format = function (fmt) { //author: meizz
var o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
};
var utils = require('utils');
var url = "https://auth.alipay.com/login/index.htm?needTransfer=true&goto=http://memberprod.alipay.com/account/reg/index.htm";
var casper = require('casper').create({
waitTimeout: 20000,
verbose: true,
logLevel: 'debug',
pageSettings: {
loadImages: true,
loadPlugins: true,
userAgent: 'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Mobile Safari/537.36'
},
viewportSize: {
width: 0, height: 0
}
});
var userName = casper.cli.args[0];
var passWord = casper.cli.args[1];
console.log("arg0: " + userName);
console.log("arg1: " + passWord);
casper.start();
casper.thenOpen(url, function () {
this.capture("screenshot/Alipay start " + new Date().Format("yyyy-MM-dd hh:mm:ss") + ".png", {
top: 0,
left: 0,
width: 0,
height: 0
});
this.evaluate(function (username, password) {
document.querySelector('#J-input-user').setAttribute('value', "");
document.querySelector('#J-input-user').setAttribute('value', username);
document.querySelector('#password_rsainput').setAttribute('value', password);
}, userName, passWord);
this.capture("screenshot/Alipay sended text " + new Date().Format("yyyy-MM-dd hh:mm:ss") + ".png", {
top: 0,
left: 0,
width: 0,
height: 0
});
this.click('#J-login-btn');
this.page.sendEvent("keypress", this.page.event.key.Enter);
this.wait(5000, function () {
this.capture("screenshot/Alipay signed in " + new Date().Format("yyyy-MM-dd hh:mm:ss") + ".png", {
top: 0,
left: 0,
width: 0,
height: 0
});
this.evaluate(function () {
this.localStorage.clear();
})
});
casper.run();
运行命令:
casperjs Alipay.js your-username your-password
有个问题,第一次输入的账户名、密码,登陆后,第二次换个账号仍显示第一个账号,还提示我密码错误,不知道怎么解决
ps:
遇到的问题:
1、node.js coding assistance is disabled
解决方法:
WebStrom->Preferences->Node.js&Npm,enabled Node.js Core Library