PYCCS_cookies.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on 2024-02-20
  4. ---------
  5. @summary: 进入前检查浏览器 PYCCS
  6. ---------
  7. @author: Lzz
  8. """
  9. import re
  10. import execjs
  11. def get_PYCCS_ck(session,proxies=False):
  12. session.proxies = proxies
  13. url = "http://www.yngp.com/page/procurement/purchaseList.html"
  14. headers = {
  15. "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",
  16. "Accept-Language": "zh-CN,zh;q=0.9",
  17. "Cache-Control": "max-age=0",
  18. "Content-Type": "application/x-www-form-urlencoded",
  19. "Origin": "http://www.yngp.com",
  20. "Proxy-Connection": "keep-alive",
  21. "Referer": "http://www.yngp.com/page/procurement/purchaseList.html",
  22. "Upgrade-Insecure-Requests": "1",
  23. "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"
  24. }
  25. ex_js = '''
  26. function get_ck(a,b,c) {
  27. var x08c924 = parseInt(a);
  28. x08c924 = x08c924 * parseInt(b);
  29. x08c924 = x08c924 + parseInt(c);
  30. x08c924 = (x08c924 * 0x3 + 0x7);
  31. if (x08c924 < 0x7b)
  32. x08c924 = x08c924 + 0x929;
  33. if (x08c924 > 0x929)
  34. x08c924 = Math['floor'](x08c924 / 0x7b);
  35. return x08c924
  36. }
  37. '''
  38. ctx = execjs.compile(ex_js)
  39. count = 0
  40. while count < 3:
  41. try:
  42. res = session.get(url, headers=headers, timeout=60, verify=False)
  43. pm_data = "".join(re.findall('\|function\|(.*?)\|version\|', res.text, re.S)).split('|')
  44. answer = ctx.call('get_ck', pm_data[1], pm_data[3], pm_data[-1])
  45. data = {
  46. "answer": f"{answer}"
  47. }
  48. resp = session.post(url.split('?')[0], headers=headers, data=data, timeout=60, verify=False)
  49. cookies = session.cookies.get_dict()
  50. if re.findall('\|function\|(.*?)\|version\|', resp.text, re.S):
  51. count += 1
  52. print(f"请求解析异常!重试 {count} 次")
  53. else:
  54. return cookies
  55. except:
  56. print("cookies_PYCCS 获取失败!")
  57. return {}