Reputation:
I am trying to scrape a website using python selenium bindings.
I want to get the content of a table using selenium.
I am quite new to python and selenium so please excuse my ignorance.
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('https://www.designmynight.com/london/bars/soho/six-storeys')
hours = driver.find_element_by_xpath('//li[@id="hours"]')
driver.find_element_by_xpath('//li[@id="hours"]').click()
hoursTable = driver.find_elements_by_css_selector("table.opening-hours")
print hoursTable
Upvotes: 1
Views: 10340
Reputation: 52685
Try below code to get required values:
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('https://www.designmynight.com/london/bars/soho/six-storeys')
hours = driver.find_element_by_xpath('//li[@id="hours"]')
hours.click()
hoursTable = driver.find_elements_by_css_selector("table.opening-times tr")
for row in hoursTable:
print(row.text)
Note that class
name of table
is not "opening-hours"
, but "opening-times"
Output:
'Day Open Close Notes'
'Monday 08:00 00:00'
'Tuesday 08:00 00:00'
'Wednesday 08:00 00:00'
'Thursday 08:00 01:00'
'Friday (today) 08:00 02:00'
'Saturday 10:00 02:00'
'Sunday 10:00 00:00'
Upvotes: 3