温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-07-07 10:49:14 来源:网络 阅读:1718 作者:素颜猪 栏目:开发技术
var casper = require('casper').create({
	clientScripts:[
		'E:/jquery.js'
	]
});
var accountLogin = '.login-form .login-tab-r a';
var hidestr = "hide",has_verify = false;

casper.start('https://cache.yisu.com/upload/information/20200312/65/243442");  
});

casper.then(function(){
	if (this.exists(accountLogin)) {
		this.echo("exists");
		this.click("#content .login-wrap .w .login-form .login-tab-r a");
	}else{
		this.echo("not exists");
	}
});

casper.then(function(){
	this.wait(2000,function() {  
        this.echo("I've waited for 2 seconds again"); 
    });
});

//可删除
casper.then(function() {  
        this.capture("accountlogin2.jpeg");  
});

casper.then(function(){
	if (this.exists("#o-authcode")) {
		this.evaluate(function(){
			var oauthcode = document.getElementById("o-authcode");
			var classValue = oauthcode.className;
			if (classValue !=null) {
				if (classValue.indexOf(hidestr) > 0) {
					has_verify = false;
				}else{
					this.captureSelector("./jdcode.jpeg","#JD_Verification1");
					has_verify = true;
				}
			}
		});
	}
});

casper.then(function(){
	this.wait(2000,function() {  
        this.echo("I've waited for 2 seconds again"); 
    });
});

casper.then(function(){
	if (has_verify) {
		this.echo("需要输入验证码");
	}else{
		this.fill('form[id="formlogin"]',{
			'loginname':'xxx',
			'nloginpwd':'xxx',

		},true);
	}
});

casper.then(function(){
	this.click(".login-btn a");
	this.echo("登录中...");
});

casper.then(function() {  
    this.wait(10000,function() {  
        this.echo("I've waited for 10 seconds again"); 
    });  
}); 

casper.then(function() {  
        this.echo('new location is ' + this.getCurrentUrl());  
        this.capture("jd.jpeg");  
});

casper.run();


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI