在 conda env 中使用 pandas.read_html() 函数时出现错误"html5lib 未找到"



当前代码:

import requests
import pandas as pd

url = 'https://docs.anaconda.com/anaconda/user-guide/getting-started/'
html = requests.get(url, verify=False).content
df_list = pd.read_html(html, flavor='bs4')
df = df_list[0]

我正在使用pandas.read_html((函数从页面中提取html,同时设置"flavor"arg="bs4"或"html5lib"。我得到错误:ImportError:html5lib找不到,请安装它。

C:Users...Miniconda3libsite-packagesurllib3connectionpool.py:1004: InsecureRequestWarning: Unverified HTTPS request is being made to host 'docs.anaconda.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning,
Traceback (most recent call last):
File "C:Users...Documents...data_scrape.py", line 11, in <module>
df_list = pd.read_html(html, flavor='bs4')
File "C:Users...Miniconda3libsite-packagespandasiohtml.py", line 1100, in read_html
displayed_only=displayed_only,
File "C:Users...Miniconda3libsite-packagespandasiohtml.py", line 891, in _parse
parser = _parser_dispatch(flav)
File "C:Users...Miniconda3libsite-packagespandasiohtml.py", line 840, in _parser_dispatch
raise ImportError("html5lib not found, please install it")
ImportError: html5lib not found, please install it

但我肯定在env中安装了bs4和html5lib。运行conda-list命令后:

conda list
# packages in environment at C:Users...Miniconda3envsweb_scrape:
#
# Name                    Version                   Build  Channel
beautifulsoup4            4.9.1            py38h32f6830_0    conda-forge
bs4                       4.9.1                         0    conda-forge
ca-certificates           2020.6.20            hecda079_0    conda-forge
certifi                   2020.6.20        py38h32f6830_0    conda-forge
html5lib                  1.1                pyh9f0ad1d_0    conda-forge
intel-openmp              2020.1                      216
libblas                   3.8.0                    16_mkl    conda-forge
libcblas                  3.8.0                    16_mkl    conda-forge
libiconv                  1.15             vc14h29686d3_5  [vc14]  anaconda
liblapack                 3.8.0                    16_mkl    conda-forge
libxml2                   2.9.10               h464c3ec_1    anaconda
libxslt                   1.1.34               he774522_0    anaconda
lxml                      4.5.2            py38he3d0fc9_0    conda-forge
mkl                       2020.1                      216
numpy                     1.18.5           py38h72c728b_0    conda-forge
openssl                   1.1.1g               he774522_0    conda-forge
pandas                    1.0.5            py38he6e81aa_0    conda-forge
pip                       20.1.1                     py_1    conda-forge
python                    3.8.3           cpython_h5fd99cc_0    conda-forge
python-dateutil           2.8.1                      py_0    conda-forge
python_abi                3.8                      1_cp38    conda-forge
pytz                      2020.1             pyh9f0ad1d_0    conda-forge
setuptools                49.2.0           py38h32f6830_0    conda-forge
six                       1.15.0             pyh9f0ad1d_0    conda-forge
soupsieve                 2.0.1            py38h32f6830_0    conda-forge
sqlite                    3.32.3               he774522_1    conda-forge
vc                        14.1                 h869be7e_1    conda-forge
vs2015_runtime            14.16.27012          h30e32a0_2    conda-forge
webencodings              0.5.1                      py_1    conda-forge
wheel                     0.34.2                     py_1    conda-forge
wincertstore              0.2                   py38_1003    conda-forge

我不知道为什么熊猫功能无法识别这些包裹。有多个其他帖子处理同一个问题,但没有一个解决方案对我有效

例如,一些类似的帖子:Python:ImportError:lxml未找到,请安装和

以上答案建议使用pip3安装软件包。当我运行这些命令时,我会得到以下信息。

pip3 install html5lib
Requirement already satisfied: html5lib in c:users...miniconda3envsweb_scrapelibsite-packages (1.1)
Requirement already satisfied: six>=1.9 in c:users...miniconda3envsweb_scrapelibsite-packages (from html5lib) (1.15.0)
Requirement already satisfied: webencodings in c:users...miniconda3envsweb_scrapelibsite-packages (from html5lib) (0.5.1)

任何关于类似问题的帮助或参考都将不胜感激!

谢谢!

尝试

conda install -c anaconda html5lib 

我也遇到了同样的问题,我不知道为什么它有效,但它对我来说很好,我在lib-lxml方面也遇到了相同的问题,并且我应用了相同的解决方案。我刚刚从Github 上的一篇帖子中复制了答案

https://github.com/jupyter/notebook/issues/3623

对于任何来这里的人。。。这个页面接近我搜索结果的顶部,我的分辨率不同,但很简单。在安装了html5lib之后,我忽略了重新启动Jupyter。Jupyter正在运行,我需要重新启动它。一旦我重新启动它,一切都很好。

相关内容

  • 没有找到相关文章

最新更新