High severity intermediate · Fix: 5-10 min

bs4.FeatureNotFound

bs4.FeatureNotFound

What this error means
BeautifulSoup raises FeatureNotFound when the specified parser is missing or HTML chunking input is malformed, causing parse failure.

Stack trace

traceback
Traceback (most recent call last):
  File "app.py", line 42, in <module>
    soup = BeautifulSoup(html_chunk, 'html.parser')
  File "/usr/local/lib/python3.9/site-packages/bs4/__init__.py", line 312, in __init__
    self.builder = builder_registry.lookup(parser)
  File "/usr/local/lib/python3.9/site-packages/bs4/builder/_registry.py", line 44, in lookup
    raise FeatureNotFound(
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: html.parser. Do you need to install a parser library?
QUICK FIX
Install missing parser libraries like 'lxml' or use Python's built-in 'html.parser' to fix BeautifulSoup FeatureNotFound errors immediately.

Why it happens

BeautifulSoup requires a parser backend like 'html.parser', 'lxml', or 'html5lib' to parse HTML chunks. If the specified parser is not installed or the HTML chunk is malformed, BeautifulSoup raises FeatureNotFound or fails to parse correctly. This often happens when the environment lacks the parser or chunk boundaries split HTML tags.

Detection

Catch bs4.FeatureNotFound exceptions during chunk parsing and log the HTML chunk content to identify missing parsers or malformed HTML before the app crashes.

Causes & fixes

1

The specified parser (e.g., 'html.parser') is not installed or available in the environment

✓ Fix

Install the required parser library (e.g., for 'lxml' run 'pip install lxml') or switch to a parser that is available like 'html.parser' which is built-in for Python 3.4+

2

HTML chunks are split mid-tag causing malformed HTML input to BeautifulSoup

✓ Fix

Ensure chunk boundaries do not split HTML tags by chunking on safe delimiters or reassembling partial tags before parsing

3

Using an outdated or incompatible BeautifulSoup version that lacks support for the requested parser

✓ Fix

Upgrade BeautifulSoup to a recent version with 'pip install --upgrade beautifulsoup4' to ensure parser compatibility

Code: broken vs fixed

Broken - triggers the error
python
from bs4 import BeautifulSoup

html_chunk = '<div><p>Broken chunk'
soup = BeautifulSoup(html_chunk, 'lxml')  # Raises FeatureNotFound if lxml not installed
print(soup.prettify())
Fixed - works correctly
python
from bs4 import BeautifulSoup

html_chunk = '<div><p>Broken chunk'
soup = BeautifulSoup(html_chunk, 'html.parser')  # Changed to built-in parser to fix error
print(soup.prettify())
Switched parser from 'lxml' to Python's built-in 'html.parser' which requires no extra installation, preventing FeatureNotFound.

Workaround

Wrap BeautifulSoup parsing in try/except bs4.FeatureNotFound and fallback to 'html.parser' or sanitize chunks to avoid malformed HTML before parsing.

Prevention

Use robust chunking logic that preserves HTML tag integrity and ensure required parser libraries are installed and compatible with your BeautifulSoup version.

Python 3.7+ · beautifulsoup4 >=4.6.0 · tested on 4.12.2
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.