【问题标题】:Couldn't find a tree builder with the features you requested: html5lib. Do you need to install a parser library?找不到具有您要求的功能的树生成器:html5lib。您需要安装解析器库吗?
【发布时间】:2019-05-16 03:50:28
【问题描述】:

我尝试在我的 python3.5 中使用soup4,但是每次我使用代码从互联网上提取某些内容时,我都会收到此错误:

 - s4\__init__.py", line 198, in __init__
       % ",".join(features)) bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: html5lib. Do you need to    install a parser library?

在本站bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?有一个同样错误的链接 我都试过了,还是报错

所有 pip 安装请求 点安装 lxml pip install beautifull soup4

我下载soup4https://www.crummy.com/software/BeautifulSoup/bs4/download/4.6/手动安装setup.py install

我已经全部更新并正常工作,但我仍然收到错误请帮助我

【问题讨论】:

  • 出现此错误的代码是什么?

标签: python beautifulsoup


【解决方案1】:

如果您使用html5lib 作为底层解析器:

soup = BeautifulSoup(html, "html5lib")
#                            ^HERE^

然后,你需要在你的python环境中安装html5lib模块:

pip install html5lib

文档参考:Installing a parser

【讨论】:

    【解决方案2】:

    对于那些即使安装了 html5lib 也出现相同错误的用户,请按照https://github.com/coursera-dl/edx-dl/issues/434 中的建议将“html5lib”替换为“html.parser”

    为我工作:)

    【讨论】:

      【解决方案3】:

      对我来说 html.parser 工作

      from bs4 import BeautifulSoup
      import urllib.request 
      response = urllib.request.urlopen('http://php.net/') 
      html = response.read()
      soup = BeautifulSoup(html,"html.parser")
      text = soup.get_text(strip=True)
      print (text)
      

      【讨论】:

        【解决方案4】:

        使用“html.parser”而不是“html5lib”。这会起作用。

        【讨论】:

          猜你喜欢
          • 2017-11-17
          • 2018-09-24
          • 2017-02-28
          • 2020-07-09
          • 2018-06-14
          • 2019-11-07
          • 2020-07-02
          • 2017-02-20
          相关资源
          最近更新 更多