我正在尝试使用python硒绑定来抓取网站。
我想使用硒获取表的内容。
我对python和selenium还是很陌生,所以请原谅我的无知。
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
最佳答案
尝试下面的代码以获得所需的值:
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)
请注意,
class
的table
名称不是"opening-hours"
,而是"opening-times"
输出:
'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'