记录不是防止忘却,只是给过往插个锚点
刚开始的时候想着给提高效率,着手写了部分用例,结果却是一直尘封至今,上面计划中要落实的替换迟迟无法落地,三年后还是靠手速来执行各种任务,今天重新拿出来,只是简单试一下最原始的验证码识别和填充,聊以自趣。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import ddddocr from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import WebDriverWait driver = webdriver.Chrome() driver.implicitly_wait(3) driver.set_window_size(1500, 1024) driver.get("http://test.com") chk_code = driver.find_element(By.ID, "v_code_img") chk_code.screenshot("code.png") ocr = ddddocr.DdddOcr() with open("code.png","rb") as fp: img = fp.read() catch = ocr.classification(img) #print(catch) driver.find_element(By.ID, "username").send_keys(self.global_config["chitu_username"]) driver.find_element(By.ID, "password").send_keys(self.global_config["chitu_password"]) driver.find_element(By.ID, "verify_code").send_keys(catch) driver.find_element(By.ID, "submit").click() |
这里的ocr使用的是ddddocr,第一次用,测试识别带各种噪音的图片准确率不是很高。git上看到有很多深度学习验证码的工程,或许有空也可以试试
https://github.com/kerlomz/captcha_trainer