Instead of Beautiful Soup: selectolax
For scraping at any real volume, use selectolax. It parses HTML with the Lexbor engine and queries it with CSS selectors, and in its author's benchmark it processed 754 home pages in 2.39 seconds against 61.02 seconds for Beautiful Soup. Beautiful Soup stays the friendlier choice for one-off scripts.
Both are for extracting data from HTML in Python.
Why selectolax is better
- Extracting the title, links, scripts and a meta tag from the home pages of the top 754 domains took 2.39 seconds with selectolax, 9.09 seconds with Beautiful Soup on lxml, and 61.02 seconds with Beautiful Soup's default html.parser, per selectolax's README.
- Its author reports a 5-30x speedup from swapping Beautiful Soup for selectolax in a text-extraction job over web archive files.
- In an independent test, Peter Bengtsson found selectolax about 7 times faster than PyQuery at extracting text from 10,000 HTML snippets.
- It is written in Cython over the Lexbor HTML5 engine and supports modern CSS selectors such as :has() and :nth-child(), plus a pseudo-class for matching text.
When to keep Beautiful Soup
Keep Beautiful Soup for small scripts where speed does not matter, for XML, and for code that edits documents through its rich tree-navigation API. It has been maintained since 2004, has thorough documentation, and was used by 34% of respondents in JetBrains' 2024 Python survey.
Switching
A rewrite of the parsing code, usually small. BeautifulSoup(html) becomes LexborHTMLParser(html), select() becomes css(), select_one() becomes css_first(), and get_text() becomes text(). Searches written with find_all() and attribute filters must be expressed as CSS selectors, and code that walks siblings or modifies the tree needs checking against selectolax's node API.
Watch out
selectolax is mainly the work of one developer and has a far smaller community, so tutorials and answers are scarcer. It parses HTML only, not XML, and offers CSS selectors rather than a find_all-style search API. Installing an older release on a new Python version can require Cython to compile it.
Also worth a look
More newer, better libraries, runtimes and developer tools
Sources
- selectolax README and benchmark
- Fast HTML parsing in Python (selectolax author)
- Peter Bengtsson: selectolax or pyquery
- Beautiful Soup home page
- Beautiful Soup (Wikipedia)
- JetBrains Python Developers Survey 2024
Judged on 2026-11-06. See every libraries, runtimes and developer tools, or all 66 replacements.