郑重声明:
本项目的所有代码和相关文章,仅用于经验技术交流分享,禁止将相关技术应用到不正当途径,因为滥用技术产生的风险与本人无关。
文章仅源自个人兴趣爱好,不涉及他用,侵权联系删
之前写过关于使用自动化工具解决验证码问题,借助打码平台(需要收费),https://blog.youkuaiyun.com/Owen_goodman/article/details/105053448
https://blog.youkuaiyun.com/Owen_goodman/article/details/105654993
也可以使用Python自带的第三库(pyautogui、PIL、pytesseract、识别引擎tesseract-ocr)识别简单的验证码。
本文主要讲述使用百度智能云进行识别验证码,相关网站:https://console.bce.baidu.com/
详情如下图:
这里简单介绍一下,简单文字的识别。
首先,注册登录,拿到APP_ID、API_KEY、SECRET_KEY.
可以调用API文档,也可以直接使用SDK文档。
下面主要是代码过程:
先装包: pip install baidu-aip
代码:
from aip import AipOcr
# Verification_code 识别验证码
def Verification_code():
""" 你的 APPID AK SK """
APP_ID = 'your APPID'
API_KEY = 'your AK'
SECRET_KEY = 'your SK'
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
""" 读取图片 """
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
image = get_file_content('./文字.jpg')
""" 如果有可选参数 """
options = {}
options["detect_direction"] = "true"
options["detect_language"] = "true"
""" 带参数调用通用文字识别, 图片参数为本地图片 """
result = client.webImage(image, options)
print("返回结果:", result)
words_result = result["words_result"]
for i in range(len(words_result)):
print(words_result)
if __name__ == "__main__":
Verification_code()
wenzi.png
结果:
返回结果: {'log_id': 7117762399842446892, 'direction': 0, 'words_result_num': 1, 'words_result': [{'words': '仪用失白'}], 'language': -1}
[{'words': '仪用失白'}]