测试过验证.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # File : 测试过验证.py
  4. # Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
  5. # Date : 2022/8/30
  6. import requests
  7. # import ddddocr
  8. from time import sleep,time
  9. from urllib.parse import urljoin,quote,unquote
  10. import requests.utils
  11. url = 'https://cokemv.me/vodsearch/斗罗大陆----------1---.html'
  12. PC_UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36'
  13. headers = {'user-agent':PC_UA}
  14. def getHome(url):
  15. # http://www.baidu.com:9000/323
  16. urls = url.split('//')
  17. homeUrl = urls[0] + '//' + urls[1].split('/')[0]
  18. return homeUrl
  19. def verifyCode(url,total_cnt=3):
  20. headers['Referer'] = getHome(url)
  21. cnt = 0
  22. ocr = ddddocr.DdddOcr()
  23. while cnt < total_cnt:
  24. s = requests.session()
  25. try:
  26. img = s.get(url="https://cokemv.me/index.php/verify/index.html?t="+str(time()), headers=headers,timeout=5).content
  27. code = ocr.classification(img)
  28. print('验证结果:',code)
  29. res = s.post(
  30. url=f"https://cokemv.me/index.php/ajax/verify_check?type=search&verify={code}",
  31. headers=headers
  32. ).json()
  33. if res["msg"] == "ok":
  34. cookies_dict = requests.utils.dict_from_cookiejar(s.cookies)
  35. cookie_str = ';'.join([f'{k}={cookies_dict[k]}' for k in cookies_dict])
  36. # return cookies_dict
  37. return cookie_str
  38. except:
  39. pass
  40. cnt += 1
  41. sleep(1)
  42. return ''
  43. r = requests.get(url,headers=headers)
  44. html = r.text
  45. print(html)
  46. if html.find('输入验证码') > -1:
  47. s = verifyCode(url)
  48. print(s)