我正在尝试使用python selenium绑定来抓取一个网站。
我想使用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
答案 0 :(得分:2)
尝试使用以下代码获取所需的值:
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
的{{1}}名称不是table
,而是"opening-hours"
输出:
"opening-times"