forked from windiboy/BUAAAutoUpdate
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathin_school.py
76 lines (63 loc) · 3.14 KB
/
in_school.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
from selenium import webdriver
from selenium.webdriver import ActionChains
import time
wechat_key = '填入你的Server酱key'
def wechat_post(text):
url = 'https://sc.ftqq.com/' + wechat_key + '.send?text='+text+time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
browser.get(url)
if __name__ == '__main__':
#这里改成你的统一认证用户名和密码
user_name = 'user'
pwd = 'password'
# 加上这两句话不打开浏览器
option = webdriver.ChromeOptions()
option.add_argument('headless') # 设置option
# 用浏览器打开打卡的网址
browser = webdriver.Chrome(options=option)
browser.get("https://app.buaa.edu.cn/uc/wap/login?redirect=https%3A%2F%2Fapp.buaa.edu.cn%2Fsite%2Fncov%2Fxisudailyup")
# 输用户名和密码
user_name_input = browser.find_element_by_css_selector('#app > div.content > div:nth-child(1) > input[type=text]')
user_name_input.send_keys(user_name)
user_pwd_input = browser.find_element_by_css_selector('#app > div.content > div:nth-child(2) > input[type=password]')
user_pwd_input.send_keys(pwd)
# 然后点击登录按钮
login_button = browser.find_element_by_css_selector('#app > div.btn')
ActionChains(browser).move_to_element(login_button).click(login_button).perform()
print('点击登陆')
# 跳转并点击获取位置按钮
# 这样写是为了等待跳转页面加载出来
while True:
try:
location_button = browser.find_element_by_css_selector('body > div.item-buydate.form-detail2.ncov-page > div > div > section > div.form > ul > li:nth-child(4) > div.text > input[type=text]')
break
except:
time.sleep(5)
# browser.get("https://app.buaa.edu.cn/site/ncov/xisudailyup")
ActionChains(browser).move_to_element(location_button).click(location_button).perform()
print('获取位置')
# 选择温度
temperature_button = browser.find_element_by_css_selector('body > div.item-buydate.form-detail2.ncov-page > div > div > section > div.form > ul > li:nth-child(5) > div > div > div:nth-child(2)')
ActionChains(browser).move_to_element(temperature_button).click(temperature_button).perform()
print('选择温度')
# 点击提交
submit_button = browser.find_element_by_css_selector('body > div.item-buydate.form-detail2.ncov-page > div > div > section > div.list-box > div > a')
ActionChains(browser).move_to_element(submit_button).click(submit_button).perform()
print('点击提交')
time.sleep(1)
# 确定
while True:
try:
confirm_button = browser.find_element_by_css_selector('#wapcf > div > div.wapcf-btn-box > div.wapcf-btn.wapcf-btn-ok')
print('提交成功')
break
except:
try:
confirm_button = browser.find_element_by_css_selector('#wapat > div > div.wapat-btn-box > div')
print('今天已提交过')
break
except:
time.sleep(0.5)
ActionChains(browser).move_to_element(confirm_button).click(confirm_button).perform()
wechat_post('提交成功')
time.sleep(1)
browser.quit()