【问题标题】:html5lib installed but BeautifulSoup cannot find it已安装 html5lib 但 BeautifulSoup 找不到它
【发布时间】:2018-03-01 20:04:28
【问题描述】:

我已经安装了 html5lib 包。我确定是因为当我尝试安装它时,我会收到一条消息说它已经安装了。

pip install html5lib
Requirement already satisfied: html5lib in ./anaconda/lib/python3.5/site-packages

我也能够成功导入该包。

import html5lib

然而,当我尝试将解析器用作 BeautifulSoup 构造函数的一部分时

soup = BeautifulSoup(response.data, 'html5lib')

我失败了

FeatureNotFound: Couldn't find a tree builder with the features you requested: html5lib. Do you need to install a parser library?

是否可以强制bs4查找已安装的解析器并成功找到html5lib?

【问题讨论】:

  • 我喜欢你想要的 'html.parser' 而不是 'html5lib'。如果没有,并且您使用的是 pycharm 之类的智能 ide,请重新启动它。
  • html5lib 是我正在寻找的。它与 html.parser 不同。查看列表crummy.com/software/BeautifulSoup/bs4/doc/#installing-a-parser
  • 正确的 python 版本?
  • @MegaIng 重新启动 IDE (Spyder) 工作。我以前在安装软件包并且没有重新启动 IDE 的情况下成功工作,所以从没想过这是我错过的东西。非常感谢!

标签: python beautifulsoup html5lib


【解决方案1】:

采纳 Megalng 的建议并重新启动 IDE。成功了!

【讨论】:

  • 是的,重新启动 IDE 或内核,如果您使用的是 Jupyter 笔记本,应该可以工作。
  • ipython也需要重启。
猜你喜欢
  • 1970-01-01
  • 2019-06-30
  • 1970-01-01
  • 1970-01-01
  • 2014-06-28
  • 2017-09-06
  • 2014-09-30
  • 2015-03-16
  • 1970-01-01
相关资源
最近更新 更多