|
3 | 3 |
|
4 | 4 | from selenium import webdriver |
5 | 5 | from selenium.common import TimeoutException |
| 6 | +from selenium.webdriver import Keys |
6 | 7 | from selenium.webdriver.common.by import By |
7 | 8 | from selenium.webdriver.support import expected_conditions as ec |
8 | 9 | from selenium.webdriver.support.ui import WebDriverWait |
@@ -56,6 +57,7 @@ def driver_get_text(locator): |
56 | 57 | def login(): |
57 | 58 | """Login to FCU course system.""" |
58 | 59 | driver.get('https://course.fcu.edu.tw/') |
| 60 | + driver_send_keys((By.XPATH, '//*[@id="ctl00_Login1_RadioButtonList1_0"]'), Keys.SPACE) |
59 | 61 | driver_send_keys((By.ID, "ctl00_Login1_UserName"), config.get("username")) |
60 | 62 | driver_send_keys((By.ID, "ctl00_Login1_Password"), config.get("password")) |
61 | 63 | driver_screenshot((By.ID, "ctl00_Login1_Image1"), "captcha.png") |
@@ -85,17 +87,20 @@ def auto_class(class_ids): |
85 | 87 | "//*[@id='ctl00_MainContent_TabContainer1_tabSelected_gvToAdd']/tbody/tr[2]/td[8]/input")) |
86 | 88 | time.sleep(0.5) |
87 | 89 | alert = driver.switch_to.alert |
88 | | - remain_pos = alert.text.strip('剩餘名額/開放名額:').split("/")[0] |
| 90 | + remain_pos = int(alert.text.strip('剩餘名額/開放名額:').split(" /")[0]) |
89 | 91 | print("課程" + class_id + ": " + alert.text) |
90 | 92 | alert.accept() |
91 | 93 |
|
92 | | - if not remain_pos == '0': |
| 94 | + if not remain_pos == 0: |
93 | 95 | driver_click((By.XPATH, |
94 | 96 | "//*[@id='ctl00_MainContent_TabContainer1_tabSelected_gvToAdd']/tbody/tr[2]/td[1]/input")) |
95 | 97 | if driver_get_text((By.XPATH, |
96 | 98 | "//*[@id='ctl00_MainContent_TabContainer1_tabSelected_lblMsgBlock']/span")) == "加選成功": |
97 | 99 | print("成功加選課程:" + class_id) |
98 | 100 | class_ids.remove(class_id) |
| 101 | + else: |
| 102 | + print("課程" + class_id + ": 加選失敗, 請確認是否已加選或衝堂/超修, 也可能被其他機器人搶走了..") |
| 103 | + pass |
99 | 104 | else: |
100 | 105 | pass |
101 | 106 | auto_class(class_ids) |
|
0 commit comments