Last active
June 17, 2016 00:39
-
-
Save rkdgusrnrlrl/5e28780ac0693fe91985b1b6738cd59d to your computer and use it in GitHub Desktop.
http://typing.tyle.io/ 의 게임을 깨지 위해 selenium 라이브러리를 써서 작성한 코드
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
# -*- coding: utf-8 -*- | |
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 | |
#pip install selenium 필요, 파이어폭스 필요(브라우저는 변경 가능) | |
driver = webdriver.Firefox() | |
driver.get('http://typing.tyle.io/') | |
#시작버튼 클릭 | |
driver.find_element_by_css_selector('#start-overlay > div:nth-child(1) > button:nth-child(1)').click() | |
#.item element 생길때까지 대기 | |
element = WebDriverWait(driver, 10).until( | |
EC.presence_of_element_located((By.CSS_SELECTOR, 'div.item:nth-child(1)')) | |
) | |
#단어 있는지 확인하고 없을 때까지 #container #words .item.you 있는 단어를 추출해 input 박스에 입력 엔터 루틴 | |
try: | |
while(driver.find_element_by_css_selector('#container #words .item.you')): | |
word = driver.find_element_by_css_selector('#container #words .item.you').text | |
print(word); | |
driver.find_element_by_css_selector('#txt-you').send_keys(word+"\n") | |
#너무 빨라서 대기 | |
driver.implicitly_wait(5) | |
except: | |
print("브라우저를 종료 합니다.") | |
driver.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment