This repository has been archived by the owner on May 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.py
104 lines (90 loc) · 3.82 KB
/
main.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
import logging
import os
from random import random
from dotenv import load_dotenv
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
load_dotenv()
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def main():
netid = os.getenv("netid")
password = os.getenv("password")
options = webdriver.ChromeOptions()
options.headless = True
options.add_argument("--window-size=1920,1080")
driver = webdriver.Chrome(options=options)
driver.get("http://jkrb.xjtu.edu.cn/EIP/user/index.htm")
wait = WebDriverWait(driver=driver, timeout=30)
wait.until((EC.url_contains("org.xjtu.edu.cn")))
elem = wait.until(
EC.presence_of_element_located((By.XPATH, '//*[@id="form1"]/input[1]'))
)
elem.send_keys(netid)
elem = wait.until(
EC.presence_of_element_located((By.XPATH, '//*[@id="form1"]/input[2]'))
)
elem.send_keys(password)
elem.send_keys(Keys.ENTER)
wait.until(EC.url_contains("jkrb.xjtu.edu.cn"))
logger.info("Successful Login")
iframe = driver.find_element_by_xpath("//iframe[@onload='__iframe_onload2()']")
driver.switch_to.frame(iframe)
iframe = driver.find_element_by_xpath("//iframe[@onload='__iframe_onload1()']")
driver.switch_to.frame(iframe)
elem = driver.find_element_by_xpath("//div[@title='本科生每日健康状况填报']")
elem.click()
driver.implicitly_wait(1)
driver.switch_to.default_content()
driver.implicitly_wait(1)
iframe = driver.find_element_by_xpath("//iframe[@onload='__iframe_onload3()']")
driver.switch_to.frame(iframe)
elem = driver.find_element_by_xpath("//li[@data-blname='每日健康填报']")
elem.click()
driver.implicitly_wait(1)
driver.switch_to.default_content()
driver.implicitly_wait(5)
try:
iframe = driver.find_element_by_xpath("//iframe[@onload='__iframe_onload4()']")
driver.switch_to.frame(iframe)
iframe = driver.find_element_by_xpath("//iframe[@onload='__iframe_onload1()']")
driver.switch_to.frame(iframe)
# check travel history
driver.find_element_by_xpath("//*[@id='mini-3$ck$1']").click()
temp = str(round(36 + random(), 1))
driver.find_element_by_xpath(
"//input[@placeholder='请准确填写体温,格式如:36.5']"
).send_keys(temp)
logger.info(f"Today's body temp. is {temp}")
driver.switch_to.default_content()
driver.implicitly_wait(1)
iframe = driver.find_element_by_xpath("//iframe[@onload='__iframe_onload4()']")
driver.switch_to.frame(iframe)
submit_btn = driver.find_element_by_xpath("//a[@id='sendBtn']")
submit_btn.click()
elem = driver.find_element_by_xpath("//*[@id='mini-17']")
elem.click()
try:
driver.switch_to.default_content()
driver.implicitly_wait(1)
iframe = driver.find_element_by_xpath(
"//iframe[@onload='__iframe_onload4()']"
)
driver.switch_to.frame(iframe)
elem = driver.find_element_by_xpath("//*[@id='mini-19$content']")
logger.info(elem.text)
except NoSuchElementException:
logger.info("Successful submit!")
except NoSuchElementException:
driver.switch_to.default_content()
iframe = driver.find_element_by_xpath("//iframe[@onload='__iframe_onload5()']")
driver.switch_to.frame(iframe)
elem = driver.find_element_by_xpath("//*[@id='messageId']")
logger.info("You've already checked in.")
logger.info(elem.text)
if __name__ == "__main__":
main()