Skip to main content

Fast HTML5 parser with CSS selectors.

Project description

selectolax logo
https://img.shields.io/pypi/v/selectolax.svg

A fast HTML5 parser with CSS selectors using Modest engine.

Installation

From PyPI using pip:

pip install selectolax

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

In [1]: from selectolax.parser import HTMLParser
   ...:
   ...: 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 = HTMLParser(html)

In [2]: tree.css_first('h1#title').text()
Out[2]: 'Hi there'

In [3]: tree.css_first('h1#title').attributes
Out[3]: {'id': 'title', 'data-updated': '20201101'}

In [4]: [node.text() for node in tree.css('.post')]
Out[4]:
['Lorem Ipsum is simply dummy text of the printing and typesetting industry. ',
 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.']
In [1]: 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))"

In [2]: for node in HTMLParser(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>

Simple Benchmark

  • Average of 10 experiments to parse and retrieve URLs from 800 Google SERP pages.
Package Time Memory (peak)
selectolax 2.38 sec. 768.11 MB
lxml 18.67 sec. 769.21 MB

License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for selectolax, version 0.2.12
Filename, size File type Python version Upload date Hashes
Filename, size selectolax-0.2.12-cp36-cp36m-macosx_10_9_x86_64.whl (739.8 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size selectolax-0.2.12-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (1.7 MB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size selectolax-0.2.12-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.9 MB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size selectolax-0.2.12-cp36-cp36m-win32.whl (555.8 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size selectolax-0.2.12-cp36-cp36m-win_amd64.whl (597.7 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size selectolax-0.2.12-cp37-cp37m-macosx_10_9_x86_64.whl (739.7 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size selectolax-0.2.12-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (1.7 MB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size selectolax-0.2.12-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.9 MB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size selectolax-0.2.12-cp37-cp37m-win32.whl (555.7 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size selectolax-0.2.12-cp37-cp37m-win_amd64.whl (597.4 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size selectolax-0.2.12-cp38-cp38-macosx_10_9_universal2.whl (1.4 MB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size selectolax-0.2.12-cp38-cp38-macosx_10_9_x86_64.whl (741.4 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size selectolax-0.2.12-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (1.8 MB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size selectolax-0.2.12-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.9 MB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size selectolax-0.2.12-cp38-cp38-win32.whl (556.8 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size selectolax-0.2.12-cp38-cp38-win_amd64.whl (600.3 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size selectolax-0.2.12-cp39-cp39-macosx_10_9_universal2.whl (1.4 MB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size selectolax-0.2.12-cp39-cp39-macosx_10_9_x86_64.whl (744.1 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size selectolax-0.2.12-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (1.7 MB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size selectolax-0.2.12-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.9 MB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size selectolax-0.2.12-cp39-cp39-win32.whl (558.1 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size selectolax-0.2.12-cp39-cp39-win_amd64.whl (601.0 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size selectolax-0.2.12-pp37-pypy37_pp73-macosx_10_9_x86_64.whl (680.5 kB) File type Wheel Python version pp37 Upload date Hashes View
Filename, size selectolax-0.2.12-pp37-pypy37_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (790.3 kB) File type Wheel Python version pp37 Upload date Hashes View
Filename, size selectolax-0.2.12-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (792.0 kB) File type Wheel Python version pp37 Upload date Hashes View
Filename, size selectolax-0.2.12-pp37-pypy37_pp73-win_amd64.whl (590.3 kB) File type Wheel Python version pp37 Upload date Hashes View
Filename, size selectolax-0.2.12.tar.gz (1.3 MB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page