Last active
January 28, 2018 18:01
-
-
Save nevadajames/0932440c49b40d56f7878c6b414ba727 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.support.ui import WebDriverWait | |
| from selenium.webdriver.support import expected_conditions as EC | |
| from selenium.webdriver.common.by import By | |
| from selenium.common.exceptions import TimeoutException | |
| driver = webdriver.Chrome() | |
| url = "http://www.fgc.cat/cat/index.asp" | |
| driver.get(url) | |
| delay = 2 # seconds | |
| try: | |
| myElem = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.ID, 'IdOfMyElement'))) | |
| print "Page is ready!" | |
| except TimeoutException: | |
| print "Loading took too much time!" | |
| start_location = raw_input("Station of Origin? ") | |
| dest_location = raw_input("Where to? ") | |
| iframe = driver.find_elements_by_tag_name('iframe')[0] | |
| driver.switch_to_frame(iframe) | |
| origin = driver.find_element_by_id("estacioOrigen") | |
| for option in origin.find_elements_by_tag_name('option'): | |
| #print option | |
| if option.text == start_location: | |
| print "Origin: " + start_location | |
| option.click() | |
| break | |
| destination = driver.find_element_by_id("estacioDesti") | |
| for option in destination.find_elements_by_tag_name('option'): | |
| #print option | |
| if option.text == dest_location: | |
| print "Destination: " + dest_location | |
| option.click() | |
| break | |
| departure_or_arrival = driver.find_element_by_xpath('//*[@id="tipusCerca"]/option[contains(text(), "Sortida")]') | |
| #date = driver.find_element_by_xpath('//*[@id="datepicker"]/value=13/1/2018"') | |
| #hour = driver.find_element_by_xpath('//*[@id="horas"]/value="4"') | |
| #minutes = driver.find_element_by_xpath('//*[@id="minutos"]/value=15"') | |
| driver.find_element_by_xpath('//*[@id="formulario"]/input').click() | |
| driver.implicitly_wait(5) | |
| results = driver.find_element_by_css_selector('#sortida_02') | |
| time_array = [] | |
| for result in results.find_elements_by_tag_name('td'): | |
| time_array.append(result) | |
| line = driver.find_element_by_xpath('//*[@id="plano"]/div/h5') | |
| route_direction = driver.find_element_by_xpath('//*[@id="capHoraris"]/h2') | |
| print "" | |
| print line.text + " " + route_direction.text | |
| print "Duration " + driver.find_element_by_xpath('//*[@id="duradaTrajecte"]').text | |
| try: | |
| print "Departure " + time_array[1].text | |
| print "Arrival " + time_array[2].text | |
| except: | |
| print "no data found" | |
| print "" | |
| print "Enjoy your journey human" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment