简体   繁体   中英

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="events_table"]"}

Need to scrape a table from https://www.ncei.noaa.gov/access/billions/events . There is a link on the website to download the table but downloaded file does not have Summary column. Tried to use following code to scrape the table:

url = 'https://www.ncei.noaa.gov/access/billions/events'
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.maximize_window()
driver.implicitly_wait(30)
driver.get(url)
df=pd.read_html(driver.find_element_by_id("events_table").get_attribute('outerHTML'))[0]

but got error

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="events_table"]"}
  (Session info: chrome=102.0.5005.61)

while I manually checked the chrome version on my mac is 100.0.4896.127 .

inspect the table component, found the table id is events_table

在此处输入图像描述

Is using find_element_by_id a must or is using find_element_by_xpath fine by you? Because this works if you were to use find_element_by_xpath and provide the id:

df=pd.read_html(driver.find_element_by_xpath('//*[@id="events-table"]').get_attribute('outerHTML'))[0]

Result:

                                                 Event  ... Deaths
0                                Western Wildfires2021  ...      8
1                   Western Drought and Heat Wave2021†  ...    229
2    Midwest Derecho and Tornado OutbreakDecember 2...  ...      1
3    Southeast, Central Tornado OutbreakDecember 2021†  ...     93
4                    Hurricane NicholasSeptember 2021†  ...      0
..                                                 ...  ...    ...
318  Severe Storms, Flash Floods, Hail, TornadoesMa...  ...     20
319                         Florida FreezeJanuary 1981  ...      0
320  Central/ Eastern Drought/ Heat WaveSummer-Fall...  ...   1260
321                         Hurricane AllenAugust 1980  ...     13
322      Southern Severe Storms and FloodingApril 1980  ...      7

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.

Related Question selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".ui flu~"} NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".selected"} NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="my id"]"} NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="header3_5"]"} Getting Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="None"]"} Python when using selenium Message: no such element: Unable to locate element: {“method”:“css selector”,“selector”:“[id=”loginUsername“]”} Unable to locate element: {“method”:“css selector”,“selector”:“[id=”identifierId“]”} in selenium Selenium NoSuchElementException - Unable to locate element: {“method”:“css selector”,“selector”:“[name=”emailAddress“]”} NoSuchElementException: Message: no such element: Unable to locate element: {"method":"name","selector":"username"} while sending text to username selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":""}
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM