# -*- coding: utf-8 -*- """ Created on 2023-09-08 --------- @summary: 进入前检查浏览器 PYCCS --------- @author: Lzz """ import re import execjs import requests def get_ck_by_js(*args): ex_js = ''' function get_ck(a,b,c) { var x08c924 = parseInt(a); x08c924 = x08c924 * parseInt(b); x08c924 = x08c924 + parseInt(c); x08c924 = (x08c924 * 0x3 + 0x7); if (x08c924 < 0x7b) x08c924 = x08c924 + 0x929; if (x08c924 > 0x929) x08c924 = Math['floor'](x08c924 / 0x7b); return x08c924 } ''' a, b, c = args ctx = execjs.compile(ex_js) return ctx.call('get_ck', a, b, c) def get_ck_by_py(*args): a, b, c = args # 将输入转换为整数 x08c924 = int(a) x08c924 *= int(b) x08c924 += int(c) # 执行运算 x08c924 = x08c924 * 0x3 + 0x7 # 0x3是十六进制的3,0x7是十六进制的7 # 条件判断 if x08c924 < 0x7b: # 0x7b是十六进制的123 x08c924 += 0x929 # 0x929是十六进制的2345 if x08c924 > 0x929: x08c924 = x08c924 // 0x7b # 使用整数除法模拟Math.floor return x08c924 def get_ck(*args, platform='py'): if platform == 'js': return get_ck_by_js(*args) else: return get_ck_by_py(*args) def find_pyccs(url, headers, proxies=None, platform=None): cookies = {} exception = None request_params = dict(headers=headers, timeout=60, verify=False) for i in range(3): with requests.Session() as session: session.proxies = proxies try: res = session.get(url, **request_params) pm_data = "".join(re.findall('\|function\|(.*?)\|version\|',res.text,re.S)).split('|') answer = get_ck(pm_data[1], pm_data[3], pm_data[-1], platform=platform) data = {"answer": f"{answer}"} url2 = url.split('?')[0] resp = session.post(url2, data=data, **request_params) cookies = session.cookies.get_dict() if re.findall('\|function\|(.*?)\|version\|', resp.text, re.S): print(f"请求解析异常!重试 {i + 1} 次") else: return cookies except Exception as e: print("cookies_PYCCS 获取失败!") exception = e break return cookies get_PYCCS_ck = find_pyccs if __name__ == "__main__": assert get_ck_by_py(1, 2, 3) == get_ck_by_js(1, 2, 3)