python---免费验证码识别库(ddddocr)
前言
# coding:utf-8 import ddddocr # 对ddddocr进行实例化 ocr = ddddocr.DdddOcr() # 读取文件 with open('test.png', 'rb') as f: # 读取图片信息 img_bytes = f.read() # 识别验证码 res = ocr.classification(img_bytes) print(res)
操作步骤
# coding:utf-8 import ddddocr import requests from selenium import webdriver ocr = ddddocr.DdddOcr() driver = webdriver.Chrome() # 打开网址页面 driver.get('http://v3pro.houjiemeishi.com/PC/pages/login/login.html') # 获取验证码图片的url地址 img_url = driver.find_element_by_class_name('codeImg').get_attribute('src') # 通过接口请求url地址,并保存在本地 r = requests.get(img_url) with open('1111.jpg', 'wb+') as f: f.write(r.content) # 再次读取图片信息 with open('1111.jpg', 'rb')as f2: img_bytes = f2.read() # 通过ddddocr进行识别验证码 res = ocr.classification(img_bytes) print('识别的验证码是:'+res) # 进行输入验证码内容 driver.find_element_by_class_name('ipt2').send_keys(res)
总结