-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_not_comment.py
136 lines (118 loc) · 6.06 KB
/
main_not_comment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import time
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
import sys
def teacher_update_not_comment():
print(f"[INFO]|{current_time()}|更新页面")
web.find_element(by=By.XPATH, value='//*[@id="ztTab_chzn"]/a').click()
web.find_element(by=By.XPATH, value='//*[@id="ztTab_chzn_o_3"]').click()
web.find_element(by=By.XPATH, value='//*[@id="queryform"]/table[1]/tbody/tr/td[2]/button').click()
def teacher_update_not_over():
print(f"[INFO]|{current_time()}|更新页面")
web.find_element(by=By.XPATH, value='//*[@id="ztTab_chzn"]/a').click()
web.find_element(by=By.XPATH, value='//*[@id="ztTab_chzn_o_1"]').click()
web.find_element(by=By.XPATH, value='//*[@id="queryform"]/table[1]/tbody/tr/td[2]/button').click()
select = Select(
web.find_element(by=By.XPATH, value='//*[@id="queryform"]/div/table/tbody/tr/td/div/ul/li[11]/select'))
select.select_by_value("9999")
def get_teacher_and_choose(web, teacher_num):
bad_teacher = []
teacher_names = []
for i in range(teacher_num):
tr = web.find_element(by=By.XPATH, value=f'//*[@id="table_report"]/tbody/tr[{i + 1}]')
teacher_name = tr.find_element(by=By.XPATH, value='./td[5]').text
teacher_names.append(teacher_name)
class_name = tr.find_element(by=By.XPATH, value='./td[4]').text
print(f"[INFO]|{current_time()}|[{i}]|{teacher_name}|{class_name}")
s = input(f"[INFO]|{current_time()}|请选择你想要差评的教师(填数字以','分隔,输入'-1'全部差评,全部好评则直接回车)>:")
if s != '':
if s == '-1':
return teacher_names
for teacher in s.split(','):
bad_teacher.append(teacher_names[eval(teacher)])
return bad_teacher
def red(text):
return '\033[31m{}\033[0m'.format(text)
def yellow(text):
return '\x1b[33m{}\x1b[0m'.format(text)
def blue(text):
return '\x1b[36m{}\x1b[0m'.format(text)
def current_time():
return yellow(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))
if __name__ == '__main__':
ACCOUNT = ''
PASSWORD = ''
teacher_num = 0
print(f"[INFO]|{current_time()}|欢迎来到北理工全自动好评系统")
ACCOUNT = input(f"[INFO]|{current_time()}|请输入需要评教的学号:>")
PASSWORD = input(f"[INFO]|{current_time()}|请输入需要评教的密码:>")
print(f"[INFO]|{current_time()}|正在打开浏览器")
# 创建浏览器对象
options = Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--window-size=1920,1080")
options.add_argument("--start-maximized")
options.add_experimental_option("detach", True)
options.add_argument('--disable-blink-features=AutomationControlled')
web = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
web.execute_cdp_cmd("Emulation.setUserAgentOverride", {
"userAgent": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0"
})
web.get('https://pj.bit.edu.cn/pjxt2.0/welcome')
print(f"[INFO]|{current_time()}|当前登录信息如下")
print(f"[INFO]|{current_time()}|用户:{blue(ACCOUNT)}")
print(f"[INFO]|{current_time()}|密码:{blue(PASSWORD)}")
start_time = time.time()
web.find_element(by=By.XPATH, value='//*[@id="username"]').send_keys(ACCOUNT)
web.find_element(by=By.XPATH, value='//*[@id="password"]').send_keys(PASSWORD, Keys.ENTER)
try:
warning = web.find_element(by=By.XPATH, value='//*[@id="showErrorTip"]').text
print(f"[{red('ERROR')}]|{current_time()}|{red('登录失败')},{red(warning)}")
sys.exit()
except Exception as e:
print(f"[INFO]|{current_time()}|登陆成功")
time.sleep(0.5)
print(f"[INFO]|{current_time()}|进入评教界面")
web.get('https://pj.bit.edu.cn/pjxt2.0/stpj/queryListStpj')
teacher_update_not_comment()
print(f"[INFO]|{current_time()}|正在获取需要评教的教师数量")
try:
teacher_num = web.find_element(by=By.XPATH,
value='//*[@id="queryform"]/div/table/tbody/tr/td/div/ul/li[1]/a/font').text
teacher_num = eval(teacher_num)
except:
pass
print(f"[INFO]|{current_time()}|共有{teacher_num}位教师需要评教")
if teacher_num != 0:
bad_teacher = get_teacher_and_choose(web, teacher_num)
for i in range(teacher_num):
teacher_update_not_comment()
teacher_name = web.find_element(by=By.XPATH, value='//*[@id="table_report"]/tbody/tr[1]/td[5]').text
print(f"[INFO]|{current_time()}|正在评教{blue(teacher_name)}")
web.find_element(by=By.XPATH, value='//*[@id="table_report"]/tbody/tr[1]/td[7]/div/a').click()
time.sleep(0.5)
check_form_list = web.find_elements(by=By.XPATH, value='//*[@id="cjForm"]/div/div[2]/div[2]/div')
for j in range(9):
check_form = check_form_list[i]
info = check_form.find_element(by=By.XPATH, value='label').text
if j in bad_teacher:
comment = blue("非常不符合")
check_form.find_element(by=By.XPATH, value='div[5]/input').click()
else:
comment = blue("非常符合")
check_form.find_element(by=By.XPATH, value='div[1]/input').click()
web.find_element(by=By.XPATH, value='//*[@id="cjForm"]/div/div[2]/div[2]/div[11]/a[1]').click()
print(f"[INFO]|{current_time()}|{blue(teacher_name)}评教结束")
time.sleep(0.5)
web.find_element(by=By.XPATH, value='/html/body/div[2]/div[2]/a').click()
time.sleep(1)
print(f"[INFO]|{current_time()}|所有评教结束")
print(f"[INFO]|{current_time()}|本次评教了{blue(teacher_num)}位教师")
end_time = time.time()
print(f"[INFO]|{current_time()}|用时{blue(end_time - start_time)}s")