YunSuoAutoJump.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on 2023-09-12
  4. ---------
  5. @summary: cookies -> security_session_mid_verify
  6. ---------
  7. @author: Lzz
  8. """
  9. import time
  10. import execjs
  11. import requests
  12. def get_mid_code(security_verify_data_url, proxies=False):
  13. session = requests.session()
  14. session.proxies = proxies
  15. headers = {
  16. "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",
  17. "Accept-Language": "zh-CN,zh;q=0.9",
  18. "Cache-Control": "no-cache",
  19. "Connection": "keep-alive",
  20. "Pragma": "no-cache",
  21. "Upgrade-Insecure-Requests": "1",
  22. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
  23. }
  24. res = session.get(security_verify_data_url, headers=headers, timeout=60, verify=False)
  25. ex_js = '''
  26. function YunSuoAutoJump(url) {
  27. function stringToHex(str) {
  28. var val = "";
  29. for (var i = 0; i < str.length; i++) {
  30. if (val == "") val = str.charCodeAt(i).toString(16); else val += str.charCodeAt(i).toString(16);
  31. }
  32. return val;
  33. }
  34. var width = 1536;
  35. var height = 864;
  36. var screendate = width + "," + height;
  37. location = url + "?security_verify_data=" + stringToHex(screendate);
  38. return location
  39. }
  40. '''
  41. ctx = execjs.compile(ex_js)
  42. yz_url = ctx.call("YunSuoAutoJump",security_verify_data_url)
  43. num = 0
  44. cookies = {}
  45. while num < 10:
  46. response = session.get(yz_url, headers=headers, timeout=60, verify=False)
  47. cookies = session.cookies.get_dict()
  48. if cookies.get('security_session_mid_verify'):
  49. break
  50. num += 1
  51. time.sleep(2)
  52. return cookies