5

I'm trying to use Beautiful Soup to parse an XML document. Here's the code where I instantiate a BeautifulSoup object:

with open(filename, encoding='utf-8') as f_:
    content = f_.read()
xml_cont = BeautifulSoup(content, 'lxml')

When I ran my code I received the following error:

  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?

I did a quick search and saw that I needed to install lxml with pip. I did so.

pip3 install lxml

However, I am still getting the error! Any ideas as to why?

Josh Katofsky
  • 511
  • 6
  • 13

1 Answers1

0

I have tried many libraries with pip, but didn't work for me.It only worked when I have installed the library from the IDE (Pycharm).

with open(file name) as file: soup = BeautifulSoup(file, "lxml")

lxml library install