“ bs4.FeatureNotFound:安装lxml后找不到具有您请求的功能的树生成器:lxml”

问题描述 投票:0回答:1

我正在尝试使用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

但是,我仍然遇到错误!关于为什么的任何想法?

python beautifulsoup pip lxml
1个回答
0
投票

BeautifulSoup(content,'html.parser')您应该试试这个

© www.soinside.com 2019 - 2024. All rights reserved.