-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUESTC.py
49 lines (43 loc) · 1.68 KB
/
UESTC.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
import time
import sys
import threading
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
class CourseSelect(object):
def __init__(
self,
driver_path: str = r"C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe",
):
option = webdriver.ChromeOptions()
option.add_argument(
r"user-data-dir=C:\Users\yulin\AppData\Local\Google\Chrome\User Data"
)
# option.add_experimental_option("excludeSwitches", ["enable-automation"])
self.browser = webdriver.Chrome(driver_path, options=option)
def selectCourse(self, *, course_nums):
browser = self.browser
browser.get("http://yjsjy.uestc.edu.cn/pyxx/pygl/pyjhxk/wsxk")
browser.switch_to.frame(
browser.find_element_by_xpath('//iframe[@id="allSubjectIframe"]')
)
for course_num in course_nums:
xpath = "//*[text()='{}']".format(course_num)
try:
course = browser.find_element_by_xpath(xpath).find_element_by_xpath(
".."
)
course_btn = course.find_element_by_xpath(".//a[@id='jhnxkBtn']")
course_btn.click()
time.sleep(1)
browser.switch_to.alert.accept()
except Exception:
print(
time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())),
"无人退课",
)
if __name__ == "__main__":
xk = CourseSelect()
while True:
xk.selectCourse(course_nums=["0808126006", "0808126007"])
time.sleep(3)