济南大学综合测评德育分自动化打分脚本

187 阅读2分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路。

一、脚本功能

本脚本实现了济南大学综合测评德育分的自动化打分。

二、运行环境

Python3 + Selenium + Chrome + Chromedriver

注意!运行环境请自行配置,这里只提供下载链接和安装命令!

Python3点击下载;提取码:6666

Selenium:通过pip命令安装 pip install selenium

Chrome点击下载

Chromedriver点击下载(驱动版本需跟Chome浏览器版本对应,下载完后放到Python目录下即可)

三、脚本效果展示

点击跳转到 哔哩哔哩 观看

四、代码详情

from selenium import webdriver
import time


# 自动填写综合测评的脚本
def script(PhoneNumber, Password):
    mobileEmulation = {'deviceName': 'iPhone 6/7/8 Plus'}  # 设置脚本的手机型号
    options = webdriver.ChromeOptions()  # 实例化浏览器选项
    options.add_experimental_option('mobileEmulation', mobileEmulation)  # 添加手机型号选项到浏览器
    Driver = webdriver.Chrome(executable_path='chromedriver.exe', chrome_options=options)  # 实例化驱动
    Driver.maximize_window()  # 最大化窗口
    Driver.get("https://zhcp.ujnxgzx.com/")  # 访问综合评价URL
    # 输入手机号和密码
    Driver.find_element_by_xpath("//div[@class='container component']/input[@type='text']").send_keys(PhoneNumber)
    Driver.find_element_by_xpath("//div[@class='container component']/input[@type='password']").send_keys(Password)
    Driver.find_element_by_xpath("//div[@class='container component']/button").click()  # 点击登录
    time.sleep(1)  # 让程序睡一会,不能删除,否则会出错
    Cnt1 = len(Driver.find_elements_by_xpath("//div[@id='PERSONS']/div"))  # 获取需要评价的学生总数
    for i in range(1, Cnt1 + 1):  # 遍历每一个学生
        Driver.find_element_by_xpath("//div[@id='PERSONS']/div[" + str(i) + "]/div/span[1]").click()  # 进入打分详情页
        print(Driver.find_element_by_xpath("//div[@class='van-nav-bar__title van-ellipsis']").text + ":评分已完成")
        Cnt2 = len(Driver.find_elements_by_xpath("//div[@class='candidate_message']/ul"))  # 获取打分选项
        for j in range(1, Cnt2 + 1):  # 遍历每一个打分项
            Driver.find_element_by_xpath("//div[@class='candidate_message']/ul[" + str(j) + "]//input").send_keys(
                "100")  # 输入分数(不用担心分数溢出,如果分数溢出,该页面的前端会自动设置成最大分)
        Driver.find_element_by_xpath("//div[@class='candidate_message']/div/button").click()  # 点击提交评分
        time.sleep(1)
    Driver.find_element_by_xpath("//div[@class='submit']").click()
    time.sleep(2)
    Driver.find_element_by_xpath(
        "//div[@class='van-hairline--top van-dialog__footer van-dialog__footer--buttons']/button[@class='van-button"
        " van-button--default van-button--large van-dialog__confirm van-hairline--left']").click()


if __name__ == '__main__':
    Tel = "填写你的手机号"  # 手机号
    Pwd = "填写你的密码"  # 密码
    script(Tel, Pwd)  # 调用脚本方法