[英]How I can get all items of table with Selenium (Python3 )?
我想從https://www.oddsportal.com/soccer/england/premier-league/wolves-newcastle-utd-nNNqedbR/頁面上的表中獲取信息。
這是一張表格,該表格會自動更改她的項目(mb與js,ajax)。
如果我編寫以下代碼, 則會出現錯誤“ HtmlElement”對象沒有屬性“ find_element_by_xpath”
url = 'https://www.oddsportal.com/soccer/england/premier-league/wolves-newcastle-utd-nNNqedbR/'
options = webdriver.ChromeOptions()
options.add_argument('headless')
driver = webdriver.Chrome(chrome_options=options)
driver.get(url)
html = lxml.html.fromstring(driver.page_source)
tbody = html.find_element_by_xpath('//*[@id="odds-data-table"]/div[1]/table/tbody')
trows = tbody.find_elements_by_tag_name("tr")
lxml是(大概是) lxml庫,因此您的html
對象是它的一個實例。 如異常所示-它沒有find_element_by_xpath()
和find_element_by_xpath()
方法,它們在硒庫中。
因此,不要使用html
對象,而要使用driver
:
tbody = driver.find_element_by_xpath('//*[@id="odds-data-table"]/div[1]/table/tbody')
trows = tbody.find_element_by_tag_name("tr")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.