bs4.FeatureNotFound:找不到具有您请求的功能的树生成器:html5lib

Posted

技术标签:

【中文标题】bs4.FeatureNotFound:找不到具有您请求的功能的树生成器:html5lib【英文标题】:bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: html5lib 【发布时间】:2018-06-14 21:18:02 【问题描述】:

我在运行我的 python 代码时遇到了这个错误:

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

于是我上网搜了一下,看了this

我检查了我安装的包,html5lib 和 6 似乎都是最新版本。

beautifulsoup4 (4.6.0)
html5lib (1.0.1)
pip (9.0.1)
setuptools (28.8.0)
six (1.11.0)
webencodings (0.5.1)

我想知道这里有什么问题?

*上下文:

import urllib.request
from bs4 import BeautifulSoup

url0 = 'http://py4e-data.dr-chuck.net/known_by_Cruz.html'

url = url0
name = list()
for i in range(0,7):
    html = urllib.request.urlopen(url).read()
    soup = BeautifulSoup(html,"html5lib")
....

当我在 jupyter notebook 中运行完全相同的代码时,它运行没有问题。

【问题讨论】:

【参考方案1】:

您尝试将 "htmllib" 替换为 "html.parser"

例如:

soup = BeautifulSoup(html,"html5lib") **->** soup = BeautifulSoup(data, "html.parser")

【讨论】:

谢谢,它成功了,但你能解释一下原因吗?一开始我只是使用soup = BeautifulSoup(html),然后我就这样写了,因为那里出现了一条警告消息,告诉我添加“html5lib”...

以上是关于bs4.FeatureNotFound:找不到具有您请求的功能的树生成器:html5lib的主要内容,如果未能解决你的问题,请参考以下文章

bs4.FeatureNotFound:找不到具有您请求的功能的树生成器:lxml。您需要安装解析器库吗?

bs4.FeatureNotFound: ... lxml 与 MacOS 和 Conda / Python 3

bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you

运行爬虫遇到奇葩的问题 bs4.FeatureNotFound: Couldn‘t find a tree builder with the features you requested: lxml.

bs4使用lxml报错

如何重新安装lxml?