3
python ddddocr 进行文字+数字验证码识别
source link: https://blog.51cto.com/royfans/5692943
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
python ddddocr 进行文字+数字验证码识别
精选 原创一、python版本
将自动安装符合自己电脑环境的最新 ddddocr。Python 环境需要小于等于 3.9。
pip install ddddocr
二、字母数字验证码
代码如下:
import ddddocr
ocr = ddddocr.DdddOcr()
with open('111.png','rb') as f:
img_bytes = f.read()
res = ocr.classification(img_bytes)
print(res)
ocr = ddddocr.DdddOcr()
with open('111.png','rb') as f:
img_bytes = f.read()
res = ocr.classification(img_bytes)
print(res)
三、完整登录一个带验证码系统的代码
from selenium import webdriver
from helium import *
import base64
import time
import ddddocr
def open_chrome():
options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
# options.add_argument('--proxy-server=socks5://127.0.0.1:1080')
options.add_experimental_option('useAutomationExtension', False)
options.add_experimental_option('excludeSwitches', ['enable-automation'])
driver = webdriver.Chrome(chrome_options=options)
driver.maximize_window()
set_driver(driver)
go_to("http://127.0.0.1:8000/login/")
write("admin","账号")
write("admin","密码")
code_base64 = driver.find_element_by_css_selector("#code + img").get_attribute('src').split("data:image/png;base64,")[-1]
img = base64.b64decode(code_base64)
# 识别验证码
ocr = ddddocr.DdddOcr(show_ad=False)
code = ocr.classification(img)
# code = res['pic_str']
write(code, '验证码')
time.sleep(3)
click(Button('登 录'))
driver.get_screenshot_as_file("test.png")
time.sleep(5)
kill_browser()
if __name__ == '__main__':
open_chrome()
from helium import *
import base64
import time
import ddddocr
def open_chrome():
options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
# options.add_argument('--proxy-server=socks5://127.0.0.1:1080')
options.add_experimental_option('useAutomationExtension', False)
options.add_experimental_option('excludeSwitches', ['enable-automation'])
driver = webdriver.Chrome(chrome_options=options)
driver.maximize_window()
set_driver(driver)
go_to("http://127.0.0.1:8000/login/")
write("admin","账号")
write("admin","密码")
code_base64 = driver.find_element_by_css_selector("#code + img").get_attribute('src').split("data:image/png;base64,")[-1]
img = base64.b64decode(code_base64)
# 识别验证码
ocr = ddddocr.DdddOcr(show_ad=False)
code = ocr.classification(img)
# code = res['pic_str']
write(code, '验证码')
time.sleep(3)
click(Button('登 录'))
driver.get_screenshot_as_file("test.png")
time.sleep(5)
kill_browser()
if __name__ == '__main__':
open_chrome()
- 赞
- 收藏
- 评论
- 分享
- 举报
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK