测试OCR.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # File : 测试OCR.py
  4. # Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
  5. # Author's Blog: https://blog.csdn.net/qq_32394351
  6. # Date : 2023/3/28
  7. import requests
  8. import base64
  9. requests.packages.urllib3.disable_warnings()
  10. 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'
  11. UA = 'Mozilla/5.0'
  12. # api = 'https://api.nn.ci/ocr/b64/text'
  13. api = 'http://192.168.10.99:9898/ocr/b64/text'
  14. api2 = 'http://dm.mudery.com:10000'
  15. api3 = 'http://localhost:5705/parse/ocr'
  16. # api4 = 'http://192.168.10.99:9898/ocr/drpy/text'
  17. api4 = 'http://drpy.nokia.press:8028/ocr/drpy/text'
  18. # api3 = 'http://cms.nokia.press:5707/parse/ocr'
  19. def test():
  20. with open('yzm1.png',mode='rb') as f:
  21. img = f.read()
  22. try:
  23. print(base64.b64encode(img).decode())
  24. # code = requests.post(api, data=base64.b64encode(img).decode(), headers={'user-agent': PC_UA}, verify=False).text
  25. # code = requests.post(api, data=base64.b64encode(img).decode(), headers={'user-agent': PC_UA}, verify=False).text
  26. # code = requests.post(api3, data={"img":base64.b64encode(img).decode()}, headers={'user-agent': PC_UA}, verify=False).text
  27. # code = requests.post(api4, data={"img":base64.b64encode(img).decode()}, headers={'user-agent': PC_UA}, verify=False).text
  28. code = requests.post(api3, data={"img":base64.b64encode(img).decode()}, headers={'user-agent': PC_UA}, verify=False).text
  29. except Exception as e:
  30. print(f'ocr识别发生错误:{e}')
  31. code = ''
  32. print(f'验证码为:{code}')
  33. return code
  34. if __name__ == '__main__':
  35. test()