哈工大自動出校申請
selenium 安裝與 chromedriver安裝可以參考以下:
https://www.cnblogs.com/lfri/p/10542797.html
安裝selenium
pip install selenium
安裝chromedriver
打開chrome訪問以下地址查看版本號:
chrome://settings/help
之後進入下載地址:
http://chromedriver.storage.googleapis.com/index.html
找到自己版本
下載
下載解壓之後找到chromedriver.exe,保存到任一一個你喜歡的目錄之後,把這個目錄添加到系統變量中(或者把chromedriver.exe直接放到Path中已經有的一個目錄下也可以)
如果添加成功,命令行輸入chromedriver會顯示如下:
代碼修改
如果不想添加環境變量,替換executable_path變量爲chromedriver路徑即可,成功添加環境變量理論上無需設置executable_path變量
記得替換你的賬號密碼和理由
range(10, 32)意爲從10號打到31號
import time
import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
# 模擬瀏覽器打開網站
# browser = webdriver.Chrome(executable_path='/usr/lib/chromium-browser/chromedriver')
for i in range(10, 32):
date_string = "2020年12月" + str(i) + "日"
browser = webdriver.Chrome(options=chrome_options,
# 替換以下chromedriver執行路徑
executable_path=r"C:\Users\Administrator\AppData\Local\Google\Chrome\Application\chromedriver.exe")
browser.get('https://xg.hit.edu.cn/zhxy-xgzs/xg_mobile/shsj/loginChange')
# 將窗口最大化
browser.maximize_window()
time.sleep(1)
browser.find_element_by_xpath('/html/body/div[1]/div[2]/button[1]').click()
time.sleep(1)
browser.find_element_by_xpath("/html/body/div[2]/div[2]/div[2]/div/div[3]/div/form/p[1]/input").send_keys(
"你的學號")
time.sleep(1)
browser.find_element_by_xpath("/html/body/div[2]/div[2]/div[2]/div/div[3]/div/form/p[2]/input[1]").send_keys(
"你的密碼")
time.sleep(1)
browser.find_element_by_xpath("/html/body/div[2]/div[2]/div[2]/div/div[3]/div/form/p[5]/button").click()
time.sleep(1)
browser.find_element_by_xpath("/html/body/div[1]/div[5]/a[3]").click() # 出入校申請
#
time.sleep(1)
browser.find_element_by_xpath("/html/body/div[2]/a/div").click() # 新增
time.sleep(1)
# browser.switch_to.alert.accept()
time.sleep(1)
browser.find_element_by_xpath("/html/body/div[1]/div/div[9]/div/label[1]").click() # 勾選臨時出校
time.sleep(1)
js = "document.getElementById('rq').removeAttribute('readonly')"
browser.execute_script(js)
browser.find_element_by_xpath("/html/body/div[1]/div/div[13]/input").send_keys(date_string) # 填寫日期
browser.find_element_by_xpath("/html/body/div[1]/div/div[15]/textarea").send_keys("喫飯") # 出校理由
browser.find_element_by_xpath("/html/body/div[3]/div[1]/input").click() # 勾選一堆東西
browser.find_element_by_xpath("/html/body/div[3]/div[2]/input").click()
browser.find_element_by_xpath("/html/body/div[3]/div[3]/input").click()
browser.find_element_by_xpath("/html/body/div[3]/div[4]/input").click()
browser.find_element_by_xpath("/html/body/div[3]/div[5]/input").click()
browser.find_element_by_xpath("/html/body/div[3]/div[6]/input").click()
browser.find_element_by_xpath("/html/body/div[3]/div[8]/input").click()
browser.find_element_by_xpath("/html/body/div[3]/div[9]/input").click()
browser.find_element_by_xpath("/html/body/div[6]").click() # 提交
# js = 'document.getElementByName("right_btn").click();' # 提交
# browser.execute_script(js)
time.sleep(1)
browser.find_element_by_xpath("/html/body/div[10]/div[3]/a[2]").click()
time.sleep(1)
print(date_string + "出校申請成功")
os.system("taskkill /im chromedriver.exe /F")
os.system("taskkill /im chrome.exe /F")