【发布时间】:2022-01-09 08:54:26
【问题描述】:
我对抓取非常陌生并且有一个问题。我正在抓取 worldometers covid 数据。因为它是动态的 - 我正在使用 selenium。
代码如下:
from selenium import webdriver
import time
URL = "https://www.worldometers.info/coronavirus/"
# Start the Driver
driver = webdriver.Chrome(executable_path = r"C:\Webdriver\chromedriver.exe")
# Hit the url and wait for 10 seconds.
driver.get(URL)
time.sleep(10)
#find class element
data= driver.find_elements_by_class_name("odd" and "even")
#for loop
for d in data:
country=d.find_element_by_xpath(".//*[@id='main_table_countries_today']").text
print(country)
当前输出:
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":".//*[@id='main_table_countries_today']"}
(Session info: chrome=96.0.4664.45)
【问题讨论】:
-
stackoverflow.com/questions/62302639/… 我很想关闭为重复项,尽管您似乎想要硒答案。
标签: python pandas dataframe selenium web-scraping