【发布时间】: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")呢?
标签: python beautifulsoup pip lxml