不错不错,写得很规范
我以前也弄过一个
[Asm] 纯文本查看 复制代码 //滑块操作(滑块元素ID,要滑动的距离)
function mockVerify(_imgId, _distance) {
var btn = document.querySelector("#" + _imgId);
var mousedown = document.createEvent('MouseEvents');
var rect = btn.getBoundingClientRect();
var x = rect.x;
var y = rect.y;
mousedown.initMouseEvent('mousedown', true, true, window, 0,
x, y, x, y, false, false, false, false, 0, null);
btn.dispatchEvent(mousedown);
var dx = 0;
var dy = 0;
var interval = setInterval(function () {
var mousemove = document.createEvent('MouseEvents');
var _x = x + dx;
var _y = y + dy;
mousemove.initMouseEvent('mousemove', true, true, window, 0,
_x, _y, _x, _y, false, false, false, false, 0, null);
btn.dispatchEvent(mousemove);
console.log("MOVE");
btn.dispatchEvent(mousemove);
if (_x - x >= _distance) {
clearInterval(interval);
var mouseup = document.createEvent('MouseEvents');
mouseup.initMouseEvent('mouseup', true, true, window, 0,
_x, _y, _x, _y, false, false, false, false, 0, null);
btn.dispatchEvent(mouseup);
console.log("END");
checkError(0);
}
else {
dx += Math.ceil(Math.random() * 30);
}
}, 100);
}
但是有的网站还有其他检测方式,用js滑动的不允许。 遇到这种情况我就调用python写的外挂来滑动
[Asm] 纯文本查看 复制代码 function handlerByPmouse(_args) {
//调用Python外挂做动作
$.ajax({
url: "http://127.0.0.1:2000",
type: "POST",
async: true,
data: _args.shift(),
dataType: "json",
success: function (__data) {
console.log(__data);
if (_args.length) {
handlerByPmouse(_args);
} else {
checkError(0);
}
}
});
}
function checkError(_n) {
var _info = $("#instructionText").text();
if (_info.indexOf("错误") != -1) {
$(".tcaptcha-embed-contrl.show-reload").click();
setTimeout(init, 3000);
console.log("滑块没滑到位");
return;
}
if (_n++ > 5 * 20) {
init();
return;
}
setTimeout(checkError, 50, _n);
}
|