最近有了一些新想法想要落实,却想要实现的功能多,又完美主义要学习的东西很多,又有学了这个忘记那个的毛病,就在这里记录一下。
import ddddocr
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import ui
from time import sleep
ocr = ddddocr.DdddOcr()
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome(options=options)
driver.implicitly_wait(4)
driver.get("http://xf.faxuan.net")
def page_is_loaded(driver):
element1 = driver.find_element(By.CLASS_NAME,"tag_hide")
if element1 != None:
return element1
wait = ui.WebDriverWait(driver, 10)
wait.until(page_is_loaded)
hide = page_is_loaded(driver)
hide.click()
while True:
# 获取元素展示内容为图片数据
pngData = driver.find_element(By.ID,'login_validateImg').screenshot_as_png
# with open('d:/tmp1.png', 'wb') as f:
# f.write(pngData)
res = ocr.classification(pngData)
print('验证码是', res)
```
网友评论