MEHMET BALIOGLU

bs4.FeatureNotFound: Couldn’t find a tree builder with the features you requested: lxml. Do you need to install a parser library?

bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?

OK, you have got the bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library? error when trying to scrape a website.

BeautifulSoup supports the HTML parser by default. If you want to use any other third-party Python parsers you need to install that external parser like(lxml).

Let’s proceed with a reproducible example:

from bs4 import BeautifulSoup

html="""<div class="description">
 <p>Here is a Paragraph</p>
 <div>Inner Div</div>
 <div>Another Div</div>
 <ul>
    <li>Item1</li>
    <li>Item2</li>
    <li>Item3</li>
 </ul>
</div>"""

#soup = BeautifulSoup(html, "lxml") JUST REPLACE THIS LINE WITH THE ONE BELOW!
soup = BeautifulSoup(html,  "html.parser")
innertext=soup.find('div', {'class':"description"}).get_text(strip=True)

print(innertext)

If you are getting this error, just replace

soup = BeautifulSoup(html, "lxml")

with

soup = BeautifulSoup(html,  "html.parser")

If changing to html.parser did not work, or if you need xml parsing exclusively, just try installing lxml. It may not be installed or you may have an outdated version.

sudo python3 -m pip install lxml --upgrade

Don’t forget to restart your IDE, otherwise it may not work.