import requests
import re, json, time
import numpy as np
import execjs
import hashlib
class XiaoXiaoLe:
def __init__(self):
self.headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
}
self.session = requests.Session()
def get_x_y(self, array):
aa = np.array(array)
print("消消乐原数组为:")
print(np.transpose(aa))
print("翻转之后的数组为:")
print(aa)
first, second = self.get_x_y_2(aa) # 这是翻转之后的数组
print(first, second)
if first is not None:
return (first[1], first[0]), (second[1], second[0])
aa = np.transpose(aa)
print("原数组:")
print(aa)
first, second = self.get_x_y_2(aa) # 这是原数组
print(first, second)
if first is not None:
return first, second
def get_x_y_2(self, aa):
for i in range(0, 3):
count = np.bincount(aa[i]) # bincount就是统计列表中数字对应的出现频率,返回一个列表
target = np.argmax(count)
if max(count) == 2:
x_pos = np.argwhere(aa[i] == target)
x_1, x_2 = x_pos[0][0], x_pos[-1][0]
for j in range(0, 3):
if j == x_1 or j == x_2:
continue
else:
if i == 0:
if target == aa[i+1][j]:
return (i, j), (i+1, j)
elif i == 1:
if target == aa[i+1][j]:
return (i, j), (i+1, j)
elif target == aa[i-1][j]:
return (i, j), (i-1, j)
elif i == 2:
if target == aa[i-1][j]:
return (i, j), (i-1, j)
else:
return None, None
def get_load(self):
load_url = "https://gcaptcha4.geetest.com/load"
code = ""
with open("xxl_js.txt", "r", encoding="utf-8") as f:
code = f.read()
run = execjs.compile(code)
challenge = run.call("uuid")
params = {
"callback": "geetest_" + str(int(time.time())*1000),
"captcha_id": "24f56dc13c40dc4a02fd0318567caef5",
"challenge":challenge,
"client_type":"web",
"risk_type":"match",
"lang":"zh"
}
try:
req = self.session.get(url=load_url, params=params, headers=self.headers)
except requests.exceptions.RequestException as e:
print("请求错误", e)
else:
if req.status_code == 200:
pattern = re.compile(r"\((.*)\)")
data = json.loads(pattern.findall(req.text)[0])["data"]
captcha_id = ""
return data["lot_number"], data["ques"], data["payload"], data["process_token"], data["pow_detail"]["datetime"], captcha_id
def get_verify(self):
lot_number, ques, payload, process_token, day_time, cap_id = self.get_load()
code = ""
with open("xxl_js.txt", "r", encoding="utf-8") as f:
code = f.read()
run = execjs.compile(code)
pow_msg = run.call("get_md5",day_time, cap_id ,lot_number)
pow_sign = hashlib.md5(pow_msg.encode("utf-8")).hexdigest()
first, second = self.get_x_y(ques)
print("需要交换的坐标为:", first, second)
userresponse = [[first[0],first[1]],[second[0], second[1]]]
result = run.call("get_w", userresponse,lot_number, pow_msg, pow_sign)
verify_url = "https://gcaptcha4.geetest.com/verify"
params = {
"callback": "geetest_" + str(int(time.time())*1000),
"captcha_id": "24f56dc13c40dc4a02fd0318567caef5",
"client_type": "web",
"lot_number":lot_number,
"risk_type":"ai",
"payload": payload,
"process_token": process_token,
"payload_protocol": 1,
"pt": 1,
"w": result
}
try:
req = self.session.get(url=verify_url, params=params, headers=self.headers)
except requests.exceptions.RequestException as e:
print("请求错误", e)
else:
if req.status_code == 200:
print(req.text)
if __name__ == "__main__":
xxl = XiaoXiaoLe()
xxl.get_verify()
这个跟滑块没有太大差别,就是找出需要交换的坐标,js代码见https://github.com/KTVICTORY18/js-