A fast HTML5 parser with CSS selectors, written in Cython, using the Lexbor engine.
Project Links
Meta
Author: Artem Golubin
Requires Python: <3.16,>=3.9
Classifiers
Development Status
- 5 - Production/Stable
Environment
- Web Environment
Intended Audience
- Developers
Natural Language
- English
Operating System
- MacOS
- Microsoft :: Windows
- OS Independent
- Unix
Programming Language
- Cython
- Python
- Python :: 3
- Python :: 3 :: Only
- Python :: 3.9
- Python :: 3.10
- Python :: 3.11
- Python :: 3.12
- Python :: 3.13
- Python :: 3.15
- Python :: Implementation :: CPython
Topic
- Internet
- Internet :: WWW/HTTP
- Software Development
- Software Development :: Libraries
- Software Development :: Libraries :: Python Modules
- Text Processing
- Text Processing :: Markup
- Text Processing :: Markup :: HTML
Typing
- Typed

A fast HTML5 parser with CSS selectors, written in Cython, using the Lexbor engine.
Installation
From PyPI using pip:
pip install selectolax
If installation fails due to compilation errors, you may need to install Cython:
pip install selectolax[cython]
This usually happens when you try to install an outdated version of selectolax on a newer version of Python.
Development version from GitHub:
git clone --recursive https://github.com/rushter/selectolax
cd selectolax
pip install -r requirements_dev.txt
python setup.py install
How to compile selectolax while developing:
make clean
make dev
Basic examples
Here are some basic examples to get you started with selectolax:
Parsing HTML and extracting text:
from selectolax.lexbor import LexborHTMLParser
html = """
<h1 id="title" data-updated="20201101">Hi there</h1>
<div class="post">Lorem Ipsum is simply dummy text of the printing and typesetting industry. </div>
<div class="post">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
"""
tree = LexborHTMLParser(html)
print(tree.css_first('h1#title').text())
# 'Hi there'
print(tree.css_first('h1#title').attributes)
# {'id': 'title', 'data-updated': '20201101'}
print([node.text() for node in tree.css('.post')])
# ['Lorem Ipsum is simply dummy text of the printing and typesetting industry. ',
# 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.']
Using advanced CSS selectors
from selectolax.lexbor import LexborHTMLParser
html = "<div><p id=p1><p id=p2><p id=p3><a>link</a><p id=p4><p id=p5>text<p id=p6></div>"
selector = "div > :nth-child(2n+1):not(:has(a))"
for node in LexborHTMLParser(html).css(selector):
print(node.attributes, node.text(), node.tag)
print(node.parent.tag)
print(node.html)
# {'id': 'p1'} p
# div
# <p id="p1"></p>
# {'id': 'p5'} text p
# div
# <p id="p5">text</p>
Using lexbor-contains CSS pseudo-class to match text
from selectolax.lexbor import LexborHTMLParser
html = "<div><p>hello </p><p id='main'>lexbor is AwesOme</p></div>"
parser = LexborHTMLParser(html)
# Case-insensitive search
results = parser.css('p:lexbor-contains("awesome" i)')
# Case-sensitive search
results = parser.css('p:lexbor-contains("AwesOme")')
assert len(results) == 1
assert results[0].text() == "lexbor is AwesOme"
Simple Benchmark
- Extract title, links, scripts and a meta tag from main pages of top 754 domains. See
examples/benchmark.pyfor more information.
| Package | Time |
|---|---|
| Beautiful Soup (html.parser) | 61.02 sec. |
| lxml / Beautiful Soup (lxml) | 9.09 sec. |
| html5_parser | 16.10 sec. |
| selectolax (Lexbor) | 2.39 sec. |
Links
- Changelog
- selectolax API reference and examples
- Video introduction to web scraping using selectolax
- How to Scrape 7k Products with Python using selectolax and httpx
- Lexbor benchmark
- Python benchmark
- Another Python benchmark
- Universal interface to lxml and selectolax
License
- lexbor engine — Apache-2.0 license
- selectolax - MIT
Contributors
Thanks to all the contributors of selectolax!
1.0.2
Oct 22, 2026
1.0.1
Oct 17, 2026
1.0.0
Oct 03, 2026
0.4.13
Sep 29, 2026
0.4.12
Sep 18, 2026
0.4.11
Jul 15, 2026
0.4.10
May 26, 2026
0.4.9
May 15, 2026
0.4.8
May 04, 2026
0.4.7
Mar 06, 2026
0.4.6
Dec 06, 2025
0.4.4
Nov 25, 2025
0.4.3
Nov 16, 2025
0.4.2
Nov 16, 2025
0.4.1
Nov 14, 2025
0.4.0
Sep 28, 2025
0.3.34
Aug 28, 2025
0.3.33
Aug 09, 2025
0.3.32
Jul 19, 2025
0.3.31
Jul 01, 2025
0.3.30
Jun 15, 2025
0.3.29
Apr 30, 2025
0.3.28
Feb 18, 2025
0.3.27
Dec 09, 2024
0.3.26
Nov 11, 2024
0.3.25
Oct 25, 2024
0.3.24
Oct 09, 2024
0.3.23
Oct 09, 2024
0.3.21
Mar 10, 2024
0.3.20
Feb 09, 2024
0.3.19
Jan 27, 2024
0.3.18
Jan 21, 2024
0.3.17
Oct 17, 2023
0.3.16
Jul 27, 2023
0.3.15
Jul 18, 2023
0.3.14
May 25, 2023
0.3.13
Apr 29, 2023
0.3.12
Jan 01, 2023
0.3.11
Sep 21, 2022
0.3.10
Sep 19, 2022
0.3.8
Aug 04, 2022
0.3.7
Mar 21, 2022
0.3.6
Nov 17, 2021
0.3.5
Oct 07, 2021
0.3.4
Sep 21, 2021
0.3.2
Aug 28, 2021
0.3.1
Aug 22, 2021
0.2.14
Aug 12, 2021
0.2.13
Jul 10, 2021
0.2.12
Jun 15, 2021
0.2.11
Apr 16, 2021
0.2.10
Dec 19, 2020
0.2.7
Aug 15, 2020
0.1.13
Apr 30, 2019
0.1.6
May 14, 2018
Wheel compatibility matrix
Files in release
selectolax-1.0.2-cp310-cp310-macosx_10_9_x86_64.whl (1.3MiB)
selectolax-1.0.2-cp310-cp310-macosx_11_0_arm64.whl (1.3MiB)
selectolax-1.0.2-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.5MiB)
selectolax-1.0.2-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.5MiB)
selectolax-1.0.2-cp310-cp310-musllinux_1_2_aarch64.whl (1.5MiB)
selectolax-1.0.2-cp310-cp310-musllinux_1_2_x86_64.whl (1.5MiB)
selectolax-1.0.2-cp310-cp310-win32.whl (1.2MiB)
selectolax-1.0.2-cp310-cp310-win_amd64.whl (1.2MiB)
selectolax-1.0.2-cp310-cp310-win_arm64.whl (1.2MiB)
selectolax-1.0.2-cp311-cp311-macosx_10_9_x86_64.whl (1.3MiB)
selectolax-1.0.2-cp311-cp311-macosx_11_0_arm64.whl (1.3MiB)
selectolax-1.0.2-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.5MiB)
selectolax-1.0.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.5MiB)
selectolax-1.0.2-cp311-cp311-musllinux_1_2_aarch64.whl (1.5MiB)
selectolax-1.0.2-cp311-cp311-musllinux_1_2_x86_64.whl (1.5MiB)
selectolax-1.0.2-cp311-cp311-win32.whl (1.2MiB)
selectolax-1.0.2-cp311-cp311-win_amd64.whl (1.2MiB)
selectolax-1.0.2-cp311-cp311-win_arm64.whl (1.2MiB)
selectolax-1.0.2-cp312-cp312-macosx_10_13_x86_64.whl (1.4MiB)
selectolax-1.0.2-cp312-cp312-macosx_11_0_arm64.whl (1.3MiB)
selectolax-1.0.2-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.5MiB)
selectolax-1.0.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.5MiB)
selectolax-1.0.2-cp312-cp312-musllinux_1_2_aarch64.whl (1.5MiB)
selectolax-1.0.2-cp312-cp312-musllinux_1_2_x86_64.whl (1.5MiB)
selectolax-1.0.2-cp312-cp312-win32.whl (1.2MiB)
selectolax-1.0.2-cp312-cp312-win_amd64.whl (1.2MiB)
selectolax-1.0.2-cp312-cp312-win_arm64.whl (1.2MiB)
selectolax-1.0.2-cp313-cp313-macosx_10_13_x86_64.whl (1.4MiB)
selectolax-1.0.2-cp313-cp313-macosx_11_0_arm64.whl (1.3MiB)
selectolax-1.0.2-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.5MiB)
selectolax-1.0.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.5MiB)
selectolax-1.0.2-cp313-cp313-musllinux_1_2_aarch64.whl (1.5MiB)
selectolax-1.0.2-cp313-cp313-musllinux_1_2_x86_64.whl (1.5MiB)
selectolax-1.0.2-cp313-cp313-win32.whl (1.1MiB)
selectolax-1.0.2-cp313-cp313-win_amd64.whl (1.2MiB)
selectolax-1.0.2-cp313-cp313-win_arm64.whl (1.2MiB)
selectolax-1.0.2-cp314-cp314-macosx_10_15_x86_64.whl (1.4MiB)
selectolax-1.0.2-cp314-cp314-macosx_11_0_arm64.whl (1.3MiB)
selectolax-1.0.2-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.5MiB)
selectolax-1.0.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.5MiB)
selectolax-1.0.2-cp314-cp314-musllinux_1_2_aarch64.whl (1.5MiB)
selectolax-1.0.2-cp314-cp314-musllinux_1_2_x86_64.whl (1.5MiB)
selectolax-1.0.2-cp314-cp314-win32.whl (1.2MiB)
selectolax-1.0.2-cp314-cp314-win_amd64.whl (1.3MiB)
selectolax-1.0.2-cp314-cp314-win_arm64.whl (1.2MiB)
selectolax-1.0.2-cp314-cp314t-macosx_10_15_x86_64.whl (1.4MiB)
selectolax-1.0.2-cp314-cp314t-macosx_11_0_arm64.whl (1.4MiB)
selectolax-1.0.2-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.5MiB)
selectolax-1.0.2-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.5MiB)
selectolax-1.0.2-cp314-cp314t-musllinux_1_2_aarch64.whl (1.5MiB)
selectolax-1.0.2-cp314-cp314t-musllinux_1_2_x86_64.whl (1.5MiB)
selectolax-1.0.2-cp314-cp314t-win32.whl (1.2MiB)
selectolax-1.0.2-cp314-cp314t-win_amd64.whl (1.3MiB)
selectolax-1.0.2-cp314-cp314t-win_arm64.whl (1.3MiB)
selectolax-1.0.2-cp315-cp315-macosx_10_15_x86_64.whl (1.4MiB)
selectolax-1.0.2-cp315-cp315-macosx_11_0_arm64.whl (1.3MiB)
selectolax-1.0.2-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.5MiB)
selectolax-1.0.2-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.5MiB)
selectolax-1.0.2-cp315-cp315-musllinux_1_2_aarch64.whl (1.5MiB)
selectolax-1.0.2-cp315-cp315-musllinux_1_2_x86_64.whl (1.5MiB)
selectolax-1.0.2-cp315-cp315-win32.whl (1.2MiB)
selectolax-1.0.2-cp315-cp315-win_amd64.whl (1.3MiB)
selectolax-1.0.2-cp315-cp315-win_arm64.whl (1.2MiB)
selectolax-1.0.2-cp315-cp315t-macosx_10_15_x86_64.whl (1.4MiB)
selectolax-1.0.2-cp315-cp315t-macosx_11_0_arm64.whl (1.4MiB)
selectolax-1.0.2-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.5MiB)
selectolax-1.0.2-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.5MiB)
selectolax-1.0.2-cp315-cp315t-musllinux_1_2_aarch64.whl (1.5MiB)
selectolax-1.0.2-cp315-cp315t-musllinux_1_2_x86_64.whl (1.5MiB)
selectolax-1.0.2-cp315-cp315t-win32.whl (1.2MiB)
selectolax-1.0.2-cp315-cp315t-win_amd64.whl (1.3MiB)
selectolax-1.0.2-cp315-cp315t-win_arm64.whl (1.3MiB)
selectolax-1.0.2-cp39-cp39-macosx_10_9_x86_64.whl (1.3MiB)
selectolax-1.0.2-cp39-cp39-macosx_11_0_arm64.whl (1.3MiB)
selectolax-1.0.2-cp39-cp39-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.5MiB)
selectolax-1.0.2-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.5MiB)
selectolax-1.0.2-cp39-cp39-musllinux_1_2_aarch64.whl (1.5MiB)
selectolax-1.0.2-cp39-cp39-musllinux_1_2_x86_64.whl (1.5MiB)
selectolax-1.0.2-cp39-cp39-win32.whl (1.2MiB)
selectolax-1.0.2-cp39-cp39-win_amd64.whl (1.2MiB)
selectolax-1.0.2-cp39-cp39-win_arm64.whl (1.2MiB)
selectolax-1.0.2.tar.gz (3.4MiB)