【Python 3】解决FeatureNotFound: Couldn‘t find a tree builder with the features you requested: lxml.

快来打我* 2022-10-26 14:04 72阅读 0赞

问题

环境:Python3.6
使用如下代码时

  1. soup = BeautifulSoup(s, html”)

报错FeatureNotFound: Couldn’t find a tree builder with the features you requested: lxml. Do you need to install a parser library?

解决办法

因为可能问题不同,有不同的解决办法
(1)第一种可能:根本没有安装lxml

  1. sudo apt-get install libxml2-dev libxslt-dev python-dev
  2. pip install beautifulsoup4
  3. sudo pip install lxml

(2)第二种可能,缺少包libxslt

  1. pip install libxslt

(3)第三种可能:lxml版本与Python3.6不兼容,需要lxml3.7.3版本

  1. pip install lxml==3.7.3

(4)直接不用lxml。使用python自带的lxml

  1. soup = BeautifulSoup(s, html.parser”)

发表评论

表情:
评论列表 (有 0 条评论,72人围观)

还没有评论,来说两句吧...

相关阅读