Last active
May 4, 2020 10:30
-
-
Save seeeturtle/c44894add15d39329791971fb788e9f4 to your computer and use it in GitHub Desktop.
EBS 온라인 클래스에서 모든 강좌를 잘 수강했는 지 확인하는 스크립트
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.support.expected_conditions import * | |
from selenium.webdriver.support.wait import WebDriverWait | |
from time import sleep | |
driver = webdriver.Chrome() | |
driver.fullscreen_window() | |
driver.implicitly_wait(10) | |
def click(xpath_or_element): | |
"default to wait until clicking is possible" | |
if isinstance(xpath_or_element, str): | |
WebDriverWait(driver, 10).until(presence_of_element_located((By.XPATH, xpath_or_element))) | |
e = driver.find_element_by_xpath(xpath_or_element) | |
driver.execute_script(f'window.scrollTo(0, {e.location["y"]})') | |
WebDriverWait(driver, 10).until(element_to_be_clickable((By.XPATH, xpath_or_element))) | |
e.click() | |
else: | |
driver.execute_script(f'window.scrollTo(0, {xpath_or_element.location["y"]})') | |
# WebDriverWait(driver, 10).until(element_to_be_clickable((By.ID, xpath_or_element.id))) | |
xpath_or_element.click() | |
driver.get('https://hoc40.ebssw.kr/onlineClass/search/onlineClassSearchView.do?schulCcode=04199&schCssTyp=online_high') | |
click('//*[@id="header"]/div[1]/div/div/div') | |
click('//*[@id="header"]/div[1]/div/div/div/div/ul/li[1]/a') | |
driver.find_element_by_xpath('//*[@id="j_username"]').send_keys('<your id>') | |
driver.find_element_by_xpath('//*[@id="j_password"]').send_keys('<your password>') | |
driver.find_element_by_xpath('//*[@id="loginViewForm"]/div/div[1]/fieldset/div/button').click() | |
click('//*[@id="header"]/div[1]/div/div/div') | |
click('//*[@id="header"]/div[1]/div/div/div/div/ul/li[1]/a') | |
l = driver.find_element_by_xpath('//*[@id="mainContent"]/div[1]/div[2]/div[2]/div/dl[2]/dd/ul') | |
subject_len = len(l.find_elements_by_tag_name('a')) | |
# 다시 driver.back()하면 WebElement를 다시 만들어내는 것 같다. | |
for i in range(subject_len): | |
# 과목 선택 | |
e = l.find_elements_by_tag_name('a')[i] | |
print(f'{e.text.replace("keyboard_arrow_right", "").strip()}:') | |
click(e) | |
lessons = driver.find_element_by_xpath('//*[@id="list_table"]/div/ul') | |
lessons = lessons.find_elements_by_tag_name('a') | |
lessons_len = len(lessons) | |
for j in range(lessons_len): | |
# 주차 선택 | |
lesson = lessons[j] | |
title = lesson.find_elements_by_tag_name('p')[0].text | |
click(lesson) | |
try: | |
check = driver.find_element_by_xpath('//*[@id="mainContent"]/div[3]/div[1]/div/div[2]/a') | |
check = check.get_attribute('innerText') | |
if '학습 이어가기' in check: | |
xs = driver.find_element_by_xpath('//*[@id="record01"]/ul') | |
uncompleted = 0 | |
for x in xs.find_elements_by_tag_name('span'): | |
if '강의 진행중' in x.text or '학습전' in x.text: | |
uncompleted += 1 | |
if uncompleted > 0: | |
print(f' - {title}: ', end='') | |
uncompleted = f'\033[91m{uncompleted}\033[0m' | |
print(uncompleted) | |
except: | |
pass | |
finally: | |
driver.back() | |
# reinitialize variables | |
lessons = driver.find_element_by_xpath('//*[@id="list_table"]/div/ul') | |
lessons = lessons.find_elements_by_tag_name('a') | |
driver.back() | |
# reinitialize variables | |
l = driver.find_element_by_xpath('//*[@id="mainContent"]/div[1]/div[2]/div[2]/div/dl[2]/dd/ul') | |
# # for e in l.find_elements_by_tag_name('a'): | |
# e = l.find_elements_by_tag_name('a')[1] | |
# e.click() | |
# # lessons = lessons.find_elements_by_tag_name('a') | |
# l = lessons.find_elements_by_tag_name('a')[2] | |
# title = l.find_elements_by_tag_name('p')[0].text | |
# print(title) | |
# click(l) | |
# # check if it's not registered | |
driver.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
물론 터미널, selenium, 파이썬(3.6+ 아마도?), 크롬 드라이버가 필요하다