需求分析:临近期末,又要在教务系统上进行教师评价,否则无法查看自己的考试成绩,但是教师评价的内容单一又繁多,所以想到用代码实现教师的自动评价
我校教务系统链接:传送
工具:python+selenium + chromedriver浏览器驱动程序
-
selenium安装:
pip install selenium
-
chromedriver驱动程序的下载
-
下载链接:https://registry.npmmirror.com/binary.html?path=chromedriver/
-
注意要下载对应chrome浏览器的版本(没有一致的,下载小于浏览器版本最接近的版本)
下载完后和代码放在同一个文件即可
-
代码实现:
from selenium.webdriver import Chrome
from selenium.webdriver.common.keys import Keys
import time
import json
web = Chrome(executable_path='chromedriver.exe')
web.get('http://jwxt2018.gxu.edu.cn/jwglxt/xtgl/index_initMenu.html?jsdm=&_t=1654144763690')
time.sleep(30) ### 手动实现登录,点击到教师评价的界面的时间,可以根据需要设置不同的时间长度
web.switch_to.window(web.window_handles[-1])
try:
while 1:
for i in range(1, 16):
code = web.find_element_by_xpath(f'//*[@id="{i}"]/td[8]').text
print(f"评价{i} 状态:{code}")
if code == '未评':
web.find_element_by_xpath(f'//*[@id="{i}"]/td[8]').click()
time.sleep(1)
all_table = web.find_elements_by_xpath('//*[@id="ajaxForm1"]/div[2]/div[1]/div[2]/table')
for table in all_table:
all_line = table.find_elements_by_xpath('./tbody/tr')
for line in all_line:
line.find_elements_by_tag_name('input')[0].click()
web.find_element_by_xpath(
'//*[@id="ajaxForm1"]/div[2]/div[1]/div[2]/table[1]/tbody/tr[4]/td[2]/div/div[2]/label/input').click()
web.find_element_by_id('btn_xspj_tj').click()
time.sleep(1)
web.find_element_by_id('btn_ok').click()
time.sleep(2)
print(f"评价{i} 状态:已评价")
web.find_element_by_xpath('//*[@id="next_pager"]/span').click()
time.sleep(1)
except Exception:
print(Exception)
演示:
注意:为了简便流程,这里我们没有用代码实现登录和点击到教师评价界面的过程,我们需要在我们设置的时间阈值之前实现登录和点击到教师评价界面的过程
涉及到隐私的登录和点击到教师评价界面的过程,我就不演示了
视频演示链接:传送



