【发布时间】:2021-07-26 01:52:52
【问题描述】:
我正在尝试将“https://umich-biostatistics.shinyapps.io/covid19/”中可用的表格加载到数据框中,并导航到页面中的“指标”部分。因为页面在打开页面后加载数据,所以我尝试使用 selenium。有人可以帮忙找出我的错误吗?
import time
from selenium import webdriver
import pandas as pd
chrome_path = r"C:\\Selenium\\chromedriver.exe"
driver = webdriver.Chrome(chrome_path)
url = 'https://umich-biostatistics.shinyapps.io/covid19/'
page = driver.get(url)
time.sleep(10)
df = pd.read_html(driver.page_source)[0]
print(df.head())
通过运行上面的代码,我得到以下错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-10-4781af4c4464> in <module>
10 time.sleep(10)
11
---> 12 df = pd.read_html(driver.page_source)[0]
13 print(df.head())
~\anaconda3\lib\site-packages\pandas\io\html.py in read_html(io, match, flavor, header, index_col, skiprows, attrs, parse_dates, thousands, encoding, decimal, converters, na_values, keep_default_na, displayed_only)
1098 na_values=na_values,
1099 keep_default_na=keep_default_na,
-> 1100 displayed_only=displayed_only,
1101 )
~\anaconda3\lib\site-packages\pandas\io\html.py in _parse(flavor, io, match, attrs, encoding, displayed_only, **kwargs)
913 break
914 else:
--> 915 raise retained
916
917 ret = []
~\anaconda3\lib\site-packages\pandas\io\html.py in _parse(flavor, io, match, attrs, encoding, displayed_only, **kwargs)
893
894 try:
--> 895 tables = p.parse_tables()
896 except ValueError as caught:
897 # if `io` is an io-like object, check if it's seekable
~\anaconda3\lib\site-packages\pandas\io\html.py in parse_tables(self)
211 list of parsed (header, body, footer) tuples from tables.
212 """
--> 213 tables = self._parse_tables(self._build_doc(), self.match, self.attrs)
214 return (self._parse_thead_tbody_tfoot(table) for table in tables)
215
~\anaconda3\lib\site-packages\pandas\io\html.py in _parse_tables(self, doc, match, attrs)
543
544 if not tables:
--> 545 raise ValueError("No tables found")
546
547 result = []
ValueError: No tables found
【问题讨论】: