-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsugang_practice.py
More file actions
105 lines (89 loc) · 6.36 KB
/
sugang_practice.py
File metadata and controls
105 lines (89 loc) · 6.36 KB
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
105
# 부산대학교 수강신청 툴
# 1. 수강신청 로그인 페이지 진입
# 2. 수강신청 페이지 진입할 때까지 로그인 버튼 반복 클릭
# 3. 수강신청 페이지 진입 후, 희망과목 수강신청 버튼 클릭
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# 1. 수강신청 로그인 페이지 진입
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-logging"])
driver = webdriver.Chrome("./chromedriver.exe" , options=options)
driver.get("https://sugang.pusan.ac.kr/sugang/Login.aspx")
# 2. 수강신청 페이지 진입할 때까지 로그인 버튼 반복 클릭
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//*[@id='txtid']")))
driver.find_element_by_xpath("//*[@id='txtid']").send_keys("201827148")
while driver.current_url != "https://sugang.pusan.ac.kr/sugang/Sugang-insert.aspx":
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//*[@id='txtid']")))
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//*[@id='txtpassword']")))
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//*[@id='btnlogin']")))
driver.find_element_by_xpath("//*[@id='txtpassword']").send_keys("msh46282651**")
driver.find_element_by_xpath("//*[@id='btnlogin']").click()
# 3. 수강신청 페이지 진입 후, 희망과목 수강신청 버튼 클릭
WebDriverWait(driver, 10).until(EC.presence_of_all_elements_located((By.XPATH, "//*[contains(@id,'_bt신청')]")))
subjects = driver.find_elements_by_xpath("//*[contains(@id,'_bt신청')]")
for i in range (0, len(subjects)-1):
subjects[i].click()
WebDriverWait(driver, 10).until(EC.presence_of_all_elements_located((By.XPATH, "//*[contains(@id,'_bt신청')]")))
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//*[@id='lbError']")))
subjects = driver.find_elements_by_xpath("//*[contains(@id,'_bt신청')]")
res = driver.find_element_by_xpath("//*[@id='lbError']")
print(f"{i}번째 과목 : {res.text}\n")
# WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='dgBasket_List_ctl02_bt신청']")))
# WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='dgBasket_List_ctl03_bt신청']")))
# WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='dgBasket_List_ctl04_bt신청']")))
# WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='dgBasket_List_ctl05_bt신청']")))
# WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='dgBasket_List_ctl06_bt신청']")))
# WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='dgBasket_List_ctl07_bt신청']")))
# WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='dgBasket_List_ctl08_bt신청']")))
# subjects = driver.find_elements_by_xpath("//*[contains(@id,'_bt신청')]")
# for i in range(0, len(subjects) - 1):
# subjects[i].click()
# WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='dgBasket_List_ctl02_bt신청']")))
# WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='dgBasket_List_ctl03_bt신청']")))
# WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='dgBasket_List_ctl04_bt신청']")))
# WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='dgBasket_List_ctl05_bt신청']")))
# WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='dgBasket_List_ctl06_bt신청']")))
# WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='dgBasket_List_ctl07_bt신청']")))
# WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='dgBasket_List_ctl08_bt신청']")))
# subjects = driver.find_elements_by_xpath("//*[contains(@id,'_bt신청')]")
# 3. 수강신청 페이지 진입 후, 희망과목 수강신청 버튼 모두 클릭
# WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//*[contains(@id,'_bt신청')]")))
# subjects = driver.find_elements_by_xpath("//*[contains(@id,'_bt신청')]")
# for subject in subjects:
# try:
# subject.click()
# WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//*[contains(@id,'_bt신청')]")))
# subjects = driver.find_elements_by_xpath("//*[contains(@id,'_bt신청')]")
# except StaleElementReferenceException:
# print("이미 수강신청 완료된 과목입니다.")
# WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//*[contains(@id,'_bt신청')]")))
# subjects = driver.find_elements_by_xpath("//*[contains(@id,'_bt신청')]")
# print(len(subjects))
# i = 1
# num_of_subject = len(subjects)
# while i <= num_of_subject - 3:
# try:
# subjects[i + 3].click()
# except StaleElementReferenceException:
# print("이미 수강신청 완료된 과목입니다.")
# WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//*[contains(@id,'_bt신청')]")))
# subjects = driver.find_elements_by_xpath("//*[contains(@id,'_bt신청')]")
# print(subjects)
# print(subjects[i])
# subjects = driver.find_elements_by_xpath("//*[contains(@id,'_bt신청')]")
# i = 1
# num_of_subjects = len(subjects)
# while i <= num_of_subjects:
# WebDriverWait(driver, 10).until(EC.presence_of_all_elements_located((By.XPATH, "//*[contains(@id,'_bt신청')]")))
# if i == 4 or 5:
# subjects[i].click()
# WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//*[@id='dgBasket_List_ctl05_bt신청']")))
# WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//*[@id='dgBasket_List_ctl06_bt신청']")))
# subjects = driver.find_elements_by_xpath("//*[contains(@id,'_bt신청')]")
# for subject in subjects:
# subject.click()
# WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//*[@id='dgBasket_List_ctl05_bt신청']")))
# WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//*[@id='dgBasket_List_ctl06_bt신청']")))
# subjects = driver.find_elements_by_xpath("//*[contains(@id,'_bt신청')]")