【问题标题】:bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: html5libbs4.FeatureNotFound:找不到具有您请求的功能的树生成器: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 中运行完全相同的代码时,它运行没有问题。

【问题讨论】:

    标签: python python-3.x beautifulsoup html5lib


    【解决方案1】:

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

    例如:

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

    【讨论】:

    • 谢谢,它成功了,但你能解释一下原因吗?一开始我只是使用soup = BeautifulSoup(html),然后我就这样写了,因为那里出现了一条警告消息,告诉我添加“html5lib”...
    猜你喜欢
    • 2017-11-17
    • 2017-02-20
    • 2020-07-02
    • 2017-02-28
    • 1970-01-01
    • 2020-07-09
    • 2019-11-07
    • 2019-05-16
    相关资源
    最近更新 更多