Using selenium I am trying to scrape a table from a website, but can't get passed the following steps without any success - help would be greatly appreciated.
table_trs = driver.find_elements('//div[@class="datatable"]/div/div[1]/div/div/table/tbody/tr')
df = table_trs
The table I am trying to scrape appears on the website as follows....
..and the section of html associated to it.....
Something is missing here or you put wrong xpath. Valid xpath will be (based on picture) "//div[@id="datatable"]/tbody/tr"
, but that will only give you the rows. You can iterate by getting the all row nubers and colums, something like //div[@id="datatable"]/tbody/tr[i]/td[j]
and then get text fro each element.
To get the <tr><\/code> s of the table by
xpath<\/code> change it to
\/\/table[@id="datatable"]\/tbody\/tr<\/code>
from selenium.webdriver.common.by import By
table_trs = driver.find_elements(By.XPATH, '//table[@id="datatable"]/tbody/tr')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.