# -*- coding: utf-8 -*- """ Created on 2024-02-20 --------- @summary: 进入前检查浏览器 PYCCS --------- @author: Lzz """ import re import execjs def get_PYCCS_ck(session,proxies=False): session.proxies = proxies url = "http://www.yngp.com/page/procurement/purchaseList.html" headers = { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Language": "zh-CN,zh;q=0.9", "Cache-Control": "max-age=0", "Content-Type": "application/x-www-form-urlencoded", "Origin": "http://www.yngp.com", "Proxy-Connection": "keep-alive", "Referer": "http://www.yngp.com/page/procurement/purchaseList.html", "Upgrade-Insecure-Requests": "1", "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" } 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 } ''' ctx = execjs.compile(ex_js) count = 0 while count < 3: try: res = session.get(url, headers=headers, timeout=60, verify=False) pm_data = "".join(re.findall('\|function\|(.*?)\|version\|', res.text, re.S)).split('|') answer = ctx.call('get_ck', pm_data[1], pm_data[3], pm_data[-1]) data = { "answer": f"{answer}" } resp = session.post(url.split('?')[0], headers=headers, data=data, timeout=60, verify=False) cookies = session.cookies.get_dict() if re.findall('\|function\|(.*?)\|version\|', resp.text, re.S): count += 1 print(f"请求解析异常!重试 {count} 次") else: return cookies except: print("cookies_PYCCS 获取失败!") return {}