Harbin Institute of Technology automatic school application (selenium+chromedriver)

Harbin Institute of Technology automatic school application


For selenium installation and chromedriver installation, please refer to the following:
https://www.cnblogs.com/lfri/p/10542797.html

Precautions

According to the reminder in the comment area, there may be inconsistencies in the interface of Benshuo, and Shuobo needs to add a line of code near line 50 according to the prompt in the comment area.
Undergraduate students currently use it normally.

Install selenium

pip install selenium

Install chromedriver

Open chrome and visit the following address to view the version number:
chrome://settings/help
Insert picture description here

Then enter the download address:
http://chromedriver.storage.googleapis.com/index.html
find your own version Insert picture description here
Download and
Insert picture description here
unzip and find chromedriver.exe, save it to any directory you like, and add this directory to the system In the variable (or you can put chromedriver.exe directly in a directory already in Path),
Insert picture description here
if the addition is successful, the command line input chromedriver will display as follows:
Insert picture description here

Code modification

If you don’t want to add environment variables, just replace the executable_path variable with the chromedriver path. In theory, you don’t need to set the executable_path variable
if you successfully add the environment variable. Remember to replace your account password and reason.
Range(10, 32) means calling from the 10th to the 31st

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")

Guess you like

Origin blog.csdn.net/qq_40363447/article/details/110781063