Zgcbwz_dtcookie.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on 2024-03-01
  4. ---------
  5. @summary: 中国船舶采购管理电子商务平台 - 账号登录
  6. ---------
  7. @author: lzz
  8. """
  9. from hashlib import md5
  10. import requests
  11. from untils.cookie_pool import LoginCookiePool
  12. from untils.get_imgcode import jy_ocr
  13. class ZgcbwzPool(LoginCookiePool):
  14. def create_cookie(self, username, password):
  15. session = requests.Session()
  16. headers = {
  17. "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.9",
  18. "Accept-Language": "zh-CN,zh;q=0.9",
  19. "Cache-Control": "no-cache",
  20. "Content-Type": "application/x-www-form-urlencoded",
  21. "Origin": "http://bs.ebuy.csemc.com",
  22. "Pragma": "no-cache",
  23. "Proxy-Connection": "keep-alive",
  24. "Referer": "http://bs.ebuy.csemc.com/login/doTdLogin.do",
  25. "Upgrade-Insecure-Requests": "1",
  26. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36"
  27. }
  28. image_text = ''
  29. url = 'http://bs.ebuy.csemc.com/authimg.img'
  30. for i in range(5):
  31. response = session.get(url)
  32. image_text = jy_ocr(
  33. response.content,
  34. "zhipu",
  35. '这是一张100以内数学计算图片验证码,中间被包裹字符是"?",图片算术内容是什么?你只需要返回图片算术内容即可,不要解释,不要返回任何其它内容'
  36. )
  37. if image_text and "=" in image_text:
  38. break
  39. def _extract(captcha, symbol):
  40. end = captcha.index(symbol)
  41. n1 = str(captcha[:end]).strip() # 被乘数/加数
  42. start = captcha.index("=")
  43. n2 = str(captcha[start + 1:]).strip() # 积/和
  44. return n1, n2
  45. def input_num(code):
  46. if "x" in code:
  47. multiplicand, product = _extract(code, "x")
  48. return round(int(product) / int(multiplicand))
  49. elif "+" in code:
  50. addend, sum_ = _extract(code, "+")
  51. return round(int(sum_) - int(addend))
  52. else:
  53. return "解析失败!"
  54. url = 'http://bs.ebuy.csemc.com/market/syscode/publicfun/getPwdRandom.do'
  55. random_res = session.post(url)
  56. random = random_res.content.decode()
  57. gg = md5(password.encode()).hexdigest().upper()
  58. pwd = md5((gg + random).encode()).hexdigest().upper()
  59. url = "http://bs.ebuy.csemc.com/login/doTdLogin.do"
  60. data = {
  61. "type": "1",
  62. "logsid": "M00004",
  63. "rememberflag": "0",
  64. "pwd": f"{pwd}",
  65. "url": "",
  66. "uid": f"{username}",
  67. "kl": "",
  68. "randCode": f"{input_num(image_text)}"
  69. }
  70. _ = session.post(url, headers=headers, data=data, timeout=20, verify=False)
  71. return requests.utils.dict_from_cookiejar(session.cookies)