Skip to content

Commit

Permalink
Fix bug - fixed bot detected bug, will query remain position first
Browse files Browse the repository at this point in the history
  • Loading branch information
HappyGroupHub committed Feb 20, 2023
1 parent bb50666 commit fa7b54b
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This python file will do the AutoClass job."""
import time

from selenium import webdriver
from selenium.common import TimeoutException
Expand All @@ -25,6 +26,10 @@ def driver_screenshot(locator, path):
WebDriverWait(driver, 10).until(ec.presence_of_element_located(locator)).screenshot(path)


def driver_get_text(locator):
return WebDriverWait(driver, 10).until(ec.presence_of_element_located(locator)).text


def login():
driver.get('https://course.fcu.edu.tw/')
driver_send_keys((By.ID, "ctl00_Login1_UserName"), config.get("username"))
Expand All @@ -44,13 +49,23 @@ def auto_class(class_ids):
driver_click((By.ID, "ctl00_MainContent_TabContainer1_tabSelected_Label3"))
for class_id in class_ids:
driver_send_keys((By.ID, "ctl00_MainContent_TabContainer1_tabSelected_tbSubID"), class_id)
try:
WebDriverWait(driver, 0.5).until(ec.presence_of_element_located((By.ID,
"//*[@id='ctl00_MainContent_TabContainer1_tabSelected_gvToDel']/tbody/tr[2]/td[1]/input")))
class_ids.remove(class_id)
except TimeoutException:

# query remain position
driver_click((By.XPATH,
"//*[@id='ctl00_MainContent_TabContainer1_tabSelected_gvToAdd']/tbody/tr[2]/td[8]/input"))
time.sleep(0.5)
alert = driver.switch_to.alert
remain_pos = alert.text.strip('剩餘名額/開放名額:').split("/")[0]
alert.accept()

if not remain_pos == '0':
driver_click((By.XPATH,
"//*[@id='ctl00_MainContent_TabContainer1_tabSelected_gvToAdd']/tbody/tr[2]/td[1]/input"))
if driver_get_text((By.XPATH, "//*[@id='ctl00_MainContent_TabContainer1_tabSelected_lblMsgBlock']/span")) == "加選成功":
print("成功加選課程:" + class_id)
class_ids.remove(class_id)
else:
pass
auto_class(class_ids)


Expand Down

0 comments on commit fa7b54b

Please sign in to comment.