安装 lxml 后“bs4.FeatureNotFound:找不到具有您请求的功能的树生成器:lxml”
Posted
技术标签:
【中文标题】安装 lxml 后“bs4.FeatureNotFound:找不到具有您请求的功能的树生成器:lxml”【英文标题】:"bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml" after installing lxml 【发布时间】:2020-07-02 01:48:56 【问题描述】:我正在尝试使用 Beautiful Soup 来解析 XML 文档。这是我实例化BeautifulSoup
对象的代码:
with open(filename, encoding='utf-8') as f_:
content = f_.read()
xml_cont = BeautifulSoup(content, 'lxml')
当我运行我的代码时,我收到了以下错误:
File "[omitted]", line 13, in [omitted]
xml_cont = BeautifulSoup(content, 'lxml')
File "/Users/Josh/Library/Python/3.7/lib/python/site-packages/bs4/__init__.py", line 228, in __init__
% ",".join(features))
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?
我做了一个快速搜索,saw 我需要用 pip 安装lxml
。我这样做了。
pip3 install lxml
但是,我仍然收到错误消息!关于原因的任何想法?
【问题讨论】:
尝试xml_cont = BeautifulSoup(content, features="xml")
,并告知结果。
@F.NiX 试过了,结果一样
xml_cont = BeautifulSoup(content, "html5lib")
呢?
【参考方案1】:
我用 pip 尝试了许多库,但对我不起作用。它只有在我从 IDE (Pycharm) 安装库时才起作用。
打开(文件名)作为文件: 汤 = BeautifulSoup(file, "lxml")
lxml library install
【讨论】:
以上是关于安装 lxml 后“bs4.FeatureNotFound:找不到具有您请求的功能的树生成器:lxml”的主要内容,如果未能解决你的问题,请参考以下文章