Python HTML parser libraries

Updated Nov 2026

Python HTML parser libraries turn HTML text into a tree of elements that code can search, read, and edit. A parser recovers from broken markup the way a browser does before a query API finds elements by CSS selector or XPath. These libraries let scrapers and AI agents pull text, links, and tables out of web pages.

Popularity

lxml has the most monthly downloads in this comparison, at 448.3M.

LibraryMonthly downloadsStarsLast releaseLicense
lxml
448.3M
3.1KSep 2026BSD-3-Clause
Beautiful Soup
322.6M
Not on GitHubJun 2026MIT
html5lib
30.4M
1.2KJun 2020MIT
selectolax
6.5M
1.7KOct 2026MIT
parsel
3.8M
Not on GitHubSep 2026BSD-3-Clause
Scrapling
1.5M
Not on GitHubNov 2026BSD-3-Clause
PyQuery
1.4M
Not on GitHubJul 2026BSD-3-Clause
Requests-HTML
398.2K
Not on GitHubFeb 2019MIT
Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

Parses HTML into ElementTree-compatible elements with XPath and HTML-specific methods.

Downloads / mo
448.3M
Stars
3.1K
Last release
6.1.3
License
BSD-3-Clause

Strengths

  • Selects elements with XPath. Query the parsed tree using XPath expressions.
  • Parses fragments as separate elements. Use fragments_fromstring when input contains multiple top-level elements.

Limitations

  • CSS selectors need another package. Install cssselect before using lxml.cssselect.
  • Recovery risks missing content. Validate extracted content before trusting heavily malformed input.

Quickstart

From lxmlhtml.txt
$ python3.13 -m pip install lxml==6.1.3
from lxml import html

document = html.fromstring("<h1>Hello</h1>")
print(document.text_content())

lxml examples

From open-source projects on GitHub

Beautiful Soup

Searches, navigates, and modifies HTML through a selected parser backend.

Downloads / mo
322.6M
Last release
4.15.0
License
MIT

Strengths

  • Combines tag searches with CSS. Use find_all and CSS selectors on the same parsed tree.
  • Retains source positions. Read sourceline and sourcepos with html.parser or html5lib.

Limitations

  • Parser choice changes broken trees. Choose a parser explicitly for consistent malformed-HTML handling.
  • Partial parsing excludes html5lib. SoupStrainer cannot skip input when using the html5lib backend.

Quickstart

From doc.md
$ python3.13 -m pip install beautifulsoup4==4.15.0
from bs4 import BeautifulSoup

document = BeautifulSoup("<h1>Hello</h1>", "html.parser")
print(document.h1.get_text())

Beautiful Soup examples

From open-source projects on GitHub

Builds HTML trees using WHATWG parsing and browser-compatible error recovery.

Downloads / mo
30.4M
Stars
1.2K
Last release
1.1
License
MIT

Strengths

  • Uses browser-style error recovery. Parse malformed HTML using the HTML specification’s recovery rules.
  • Can reject parse errors. Set strict=True to raise exceptions on parse errors.

Limitations

  • lxml trees lose some nodes. Root-level text or comments trigger DataLossWarning with the lxml tree builder.
  • lxml trees exclude PyPy. Choose another tree backend when running on PyPy.

Quickstart

From README.rst
$ python3.13 -m pip install html5lib==1.1
import html5lib

document = html5lib.parse("<h1>Hello</h1>")
print(document.tag)

html5lib examples

From open-source projects on GitHub

Parses HTML with Lexbor and queries its tree using CSS selectors.

Downloads / mo
6.5M
Stars
1.7K
Last release
1.0.2
License
MIT

Strengths

  • Queries with complex CSS. Use compound selectors to target matching nested elements.
  • Parses fragments without document wrappers. Set is_fragment=True to avoid inserting synthetic document elements.

Limitations

  • Template contents need separate traversal. Use template_fragments; ordinary css queries skip template contents.

Quickstart

From README.md
$ python3.13 -m pip install selectolax==1.0.2
from selectolax.lexbor import LexborHTMLParser

document = LexborHTMLParser("<h1>Hello</h1>")
print(document.css_first("h1").text())

selectolax examples

From open-source projects on GitHub

Extracts data from HTML and XML with XPath and CSS selectors.

Downloads / mo
3.8M
Last release
1.12.1
License
BSD-3-Clause

Quickstart

From usage.html
$ python3.13 -m pip install parsel==1.12.1
from parsel import Selector

document = Selector(text="<h1>Hello</h1>")
print(document.css("h1::text").get())

parsel examples

From open-source projects on GitHub

Scrapes the web through a high-performance Python framework.

Downloads / mo
1.5M
Last release
0.5.1
License
BSD-3-Clause

Quickstart

From parser.py
$ python3.13 -m pip install scrapling==0.5.1
from scrapling.parser import Selector

document = Selector("<h1>Hello</h1>")
print(document.css("h1::text").get())

Scrapling examples

From open-source projects on GitHub

Queries HTML in Python with a jQuery-like API.

Downloads / mo
1.4M
Last release
2.1.0
License
BSD-3-Clause

Quickstart

From pyquery.py
$ python3.13 -m pip install pyquery==2.1.0
from pyquery import PyQuery

document = PyQuery("<h1>Hello</h1>")
print(document("h1").text())

PyQuery examples

From open-source projects on GitHub

Parses HTML with a human-friendly API.

Downloads / mo
398.2K
Last release
0.10.0
License
MIT

Quickstart

From requests_html.py
$ python3.13 -m pip install requests-html==0.10.0 lxml-html-clean==0.4.6
from requests_html import HTML

document = HTML(html="<h1>Hello</h1>")
print(document.find("h1", first=True).text)

Requests-HTML examples

From open-source projects on GitHub

FAQ

Beautiful Soup suits most scraping, with tag navigation over a choice of parser backends. lxml suits fast parsing with full XPath. selectolax suits high-volume parsing with CSS selectors.

Beautiful Soup searches, navigates, and modifies HTML through a parser backend such as the built-in html.parser, lxml, or html5lib. The backend decides how it recovers from broken markup.

Scrapling is a web scraping framework with CSS and XPath extraction. It can relocate elements after a page layout changes by matching their structure.

lxml parses quickly and supports full XPath and element editing. Beautiful Soup offers a friendlier search API and can use lxml as its parser backend.

selectolax parses HTML with the Lexbor engine and queries the tree with CSS selectors. It has no full XPath evaluator.

For coding agents

Found your HTML parser library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official