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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
from time import sleep from tkinter import BROWSE from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.common.by import By import ddddocr
username = "XXX" passwd = "XXX"
browser = webdriver.Chrome(ChromeDriverManager( ).install())
url = "https://yabook.blog/e/member/login/#EmpireCMS" def yanzhengma(): a_href = browser.find_element(By.XPATH,r'//*[@id="loginshowkey"]/a').click() sleep(3) print("点击显示验证码成功") sleep(1)
png = browser.find_element(By.XPATH,r'//*[@id="loginKeyImg"]') png.screenshot('yzm.png') print("保存验证码成功") sleep(1) ocr = ddddocr.DdddOcr() with open('yzm.png','rb') as f: img_bytes = f.read() res = ocr.classification(img_bytes) yzm = browser.find_element(By.XPATH,r'//*[@id="key"]') yzm.send_keys(res) try: browser.get(url) user = browser.find_element(By.XPATH,r'//*[@id="username"]') user.send_keys(username) password = browser.find_element(By.XPATH,r'//*[@id="password"]') password.send_keys(passwd) sleep(2) print("账号密码已输入成功") yanzhengma() sleep(2) login = browser.find_element(By.XPATH,r'/html/body/div[1]/div[1]/div[2]/div[2]/div[1]/div/form/div[6]/input').click() sleep(4) qiandao = browser.find_element(By.XPATH,r'/html/body/div[1]/div[1]/div[2]/div[2]/div[1]/div/table[2]/tbody/tr[6]/td[2]/a').click() except: print("失败") browser.quit()
|