代码拉取完成,页面将自动刷新
from selenium import webdriver
from selenium.webdriver.common.by import By
from PIL import Image
import ddddocr
import time
bro = webdriver.Edge()
bro.get('http://jw.qdu.edu.cn/homepage/index.do')
bro.save_screenshot('full_page.png')
code_img_ele = bro.find_element(By.ID,'jcaptcha')
location = code_img_ele.location
size = code_img_ele.size
rangle = (
1.5*int(location['x']),1.5*int(location['y']),1.5*int(location['x']+size['width']),1.5*int(location['y']+size['height']))
i = Image.open('./full_page.png')
name = './coding_result.png'
frame = i.crop(rangle)
frame.save(name)
ocr = ddddocr.DdddOcr()
with open('coding_result.png','rb') as fp:
img_data = fp.read()
pass
res = ocr.classification(img_data)
account = bro.find_element(By.XPATH,'//*[@id="login"]/tbody/tr[4]/td/input')
account.send_keys('2021200218')
password = bro.find_element(By.XPATH,'//*[@id="login"]/tbody/tr[6]/td/input')
password.send_keys('11.100.11.10.1')
security_code = bro.find_element(By.XPATH,'//*[@id="login"]/tbody/tr[8]/td/input')
security_code.send_keys(res)
log_in = bro.find_element(By.CLASS_NAME,'button')
log_in.click()
time.sleep(10)
bro.quit()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。