forked from Limour-dev/Fudan_pingjiao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwork.py
75 lines (64 loc) · 2.64 KB
/
work.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
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
import time
from random import random
usrname = ''
password = ''
sleep_time = 10 # select how many seconds to wait in finishing each task
driver = webdriver.Chrome()
url = "https://yzsfwapp.fudan.edu.cn/gsapp/sys/wspjappfudan/*default/index.do"
driver.get(url)
usr = driver.find_element(By.ID, 'username')
pwd = driver.find_element(By.ID, 'password')
submit = driver.find_element(By.ID, 'idcheckloginbtn')
usr.send_keys(usrname) #填入uis用户名
pwd.send_keys(password) #填入uis密码
submit.click()
time.sleep(3)
# if there's shut, shut it.
try:
driver.find_element(By.ID, 'guideShut').click()
# shut.click()
except NoSuchElementException as e:
pass
while True:
driver.get(url)
time.sleep(2)
try:
driver.find_element(By.ID, 'guideShut').click()
except NoSuchElementException as e:
pass
xpath = '/html/body/main/article/section/div[2]/div/div[2]/div/div/div/div/div/div'
task_list = driver.find_elements(By.XPATH, xpath)
task_completed = ['success' in i.find_element(By.XPATH, './div').get_attribute('class') for i in task_list]
# print("Total tasks:", len(task_list), "Finished tasks:", sum(task_completed))
print(f"Tasks to go: {len(task_list)-sum(task_completed)}, Total tasks: {len(task_list)}")
if sum(task_completed) == len(task_list):
print("All tasks finished! Exiting...")
break
for i in range(len(task_list)): # Go to the first unfinished task.
if not task_completed[i]:
print(task_list[i].find_element(By.XPATH, './div/div[2]').get_attribute('title'))
task_list[i].click()
break
# if there's shut, shut it.
time.sleep(3)
try:
driver.find_element(By.ID, 'guideShut').click()
except NoSuchElementException as e:
pass
# find all the radio buttons
xpath = '/html/body/div[14]/div/div[1]/section/div/div[*]/div'
radio_list = driver.find_elements(By.CLASS_NAME, 'paper_tm')
print("Total radio buttons: ", len(radio_list))
for i in range(len(radio_list)):
grad = 1 if random() < 0.93 else 2 # the chance of choosing the first one
node = radio_list[i].find_element(By.XPATH, f'./div/label[{grad}]')
# print(node.find_element(By.XPATH, './span').text)
driver.execute_script("arguments[0].click();", node)
driver.implicitly_wait(1)
# confirm and submit
time.sleep(sleep_time)
driver.find_element(By.XPATH, '//a[text()="提交"]').click()
driver.find_element(By.XPATH, '//a[text()="确定"]').click()