Skip to content

Commit 683bc98

Browse files
committed
Fix bug - hard change language to cn, and make remain_pos an int type
1 parent 188b8fa commit 683bc98

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

app.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from selenium import webdriver
55
from selenium.common import TimeoutException
6+
from selenium.webdriver import Keys
67
from selenium.webdriver.common.by import By
78
from selenium.webdriver.support import expected_conditions as ec
89
from selenium.webdriver.support.ui import WebDriverWait
@@ -56,6 +57,7 @@ def driver_get_text(locator):
5657
def login():
5758
"""Login to FCU course system."""
5859
driver.get('https://course.fcu.edu.tw/')
60+
driver_send_keys((By.XPATH, '//*[@id="ctl00_Login1_RadioButtonList1_0"]'), Keys.SPACE)
5961
driver_send_keys((By.ID, "ctl00_Login1_UserName"), config.get("username"))
6062
driver_send_keys((By.ID, "ctl00_Login1_Password"), config.get("password"))
6163
driver_screenshot((By.ID, "ctl00_Login1_Image1"), "captcha.png")
@@ -85,17 +87,20 @@ def auto_class(class_ids):
8587
"//*[@id='ctl00_MainContent_TabContainer1_tabSelected_gvToAdd']/tbody/tr[2]/td[8]/input"))
8688
time.sleep(0.5)
8789
alert = driver.switch_to.alert
88-
remain_pos = alert.text.strip('剩餘名額/開放名額:').split("/")[0]
90+
remain_pos = int(alert.text.strip('剩餘名額/開放名額:').split(" /")[0])
8991
print("課程" + class_id + ": " + alert.text)
9092
alert.accept()
9193

92-
if not remain_pos == '0':
94+
if not remain_pos == 0:
9395
driver_click((By.XPATH,
9496
"//*[@id='ctl00_MainContent_TabContainer1_tabSelected_gvToAdd']/tbody/tr[2]/td[1]/input"))
9597
if driver_get_text((By.XPATH,
9698
"//*[@id='ctl00_MainContent_TabContainer1_tabSelected_lblMsgBlock']/span")) == "加選成功":
9799
print("成功加選課程:" + class_id)
98100
class_ids.remove(class_id)
101+
else:
102+
print("課程" + class_id + ": 加選失敗, 請確認是否已加選或衝堂/超修, 也可能被其他機器人搶走了..")
103+
pass
99104
else:
100105
pass
101106
auto_class(class_ids)

0 commit comments

Comments
 (0)