繁体   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