我正在尝试使用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?
我进行了快速搜索,并用pip安装了saw。我是这样做的。
lxml
但是,我仍然遇到错误!关于为什么的任何想法?
BeautifulSoup(content,'html.parser')您应该试试这个