實(shí)現(xiàn)搶課自由!Python自動(dòng)登錄教務(wù)搶課

from selenium import webdriver from selenium.webdriver.common.by import By import time from PIL import Image import pytesseract #初始化瀏覽器 driver = webdriver.Edge() driver.get('http://my.nau.edu.cn') time.sleep(1) driver.maximize_window() time.sleep(1) #獲取驗(yàn)證碼 code_location=driver.find_element(By.CLASS_NAME,'codeImg') driver.save_screenshot('.\\code1.png') location=code_location.location size=code_location.size left=location['x'] top=location['y'] right=left+size['width'] bottom=top+size['height'] img=Image.open('.\\code1.png') frame=img.crop((left,top,right,bottom)) # frame.show() frame.save('.\\code.png') path='code.png' code_img=Image.open(path) code=pytesseract.image_to_string(code_img) #輸入信息并登錄 driver.find_element(By.ID,'username').send_keys('學(xué)號(hào)') driver.find_element(By.ID,'password').send_keys('密碼') driver.find_element(By.ID,'authcode').send_keys(code) time.sleep(1) #教務(wù)在線 driver.find_element(By.XPATH,'/html/body/div/div[3]/div/div/div[1]/div[1]/div/div/div/div/div/div/div[2]/div/ul/li[1]/p').click() time.sleep(1) #當(dāng)前頁(yè)面操作 driver.switch_to.window(driver.window_handles[1]) driver.find_element(By.XPATH,'/html/body/div[8]/div[1]/div[3]/a').click() #在線選課 driver.find_element(By.XPATH,'//*[@id="tt_easyui_tree_23"]/span[3]').click() #通識(shí)教育任選課 driver.find_element(By.XPATH,'//*[@id="tt_easyui_tree_40"]/span[4]/a').click() # 英語(yǔ)后續(xù)課程 # driver.find_element(By.XPATH,'//*[@id="tt_easyui_tree_43"]/span[4]/a').click() # time.sleep(1) #跳轉(zhuǎn)到選課iframe界面 iframe=driver.find_element(By.XPATH,'//*[@id="FrameContent"]') driver.switch_to.frame(iframe) #課程序號(hào) driver.find_element(By.XPATH,'//*[@id="CourseList"]/tbody/tr[200]/td[1]/input').click() #確認(rèn)選課信息 driver.find_element(By.XPATH,'//*[@id="SubmitBtn1"]/a/span/span[1]').click()
標(biāo)簽: