簡體   English   中英

NoSuchElementException:消息:沒有這樣的元素:無法找到元素:{"method":"css selector","selector":"[id="events_table"]"}

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

需要從https://www.ncei.noaa.gov/access/billions/events刮一張桌子。 網站上有下載表格的鏈接,但下載的文件沒有“摘要”列。 嘗試使用以下代碼來抓取表格:

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]

但有錯誤

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

而我手動檢查我的 mac 上的 chrome 版本是100.0.4896.127

檢查表組件,發現表 id 是events_table

在此處輸入圖像描述

是必須使用find_element_by_id還是您可以使用find_element_by_xpath 因為如果您要使用find_element_by_xpath並提供 id,則此方法有效:

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

結果:

                                                 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

相關問題 selenium.common.exceptions.NoSuchElementException:消息:沒有這樣的元素:無法找到元素:{“方法”:“css選擇器”,“選擇器”:“.ui流感~”} NoSuchElementException:消息:沒有這樣的元素:無法定位元素:{“method”:“css selector”,“selector”:“.selected”} NoSuchElementException:消息:沒有這樣的元素:無法找到元素:{"method":"xpath","selector":"//*[@id="my id"]"} NoSuchElementException:消息:沒有這樣的元素:無法定位元素:{“method”:“xpath”,“selector”:“//* [@id =“header3_5”]”} 收到消息:沒有這樣的元素:無法找到元素:{"method":"css selector","selector":"[id="None"]"} Python 使用 selenium 時 消息:沒有這樣的元素:無法找到元素:{“method”:“css selector”,“selector”:“[id=”loginUsername“]”} 無法找到硒中的元素:{“方法”:“ css選擇器”,“選擇器”:“ [id =” identifierId”]”} Selenium NoSuchElementException-無法找到元素:{“方法”:“ css選擇器”,“選擇器”:“ [[名稱=”電子郵件地址”]”} NoSuchElementException:消息:沒有這樣的元素:無法定位元素:{“方法”:“名稱”,“選擇器”:“用戶名”},同時向用戶名發送文本 selenium.common.exceptions.NoSuchElementException:消息:沒有這樣的元素:無法定位元素:{"method":"xpath","selector":""}
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM