Skip to main content

astral-html


A very fast HTML parser with CSS selectors for Python web scrapers. It’s written in Rust and uses the astral-html tokenizer crate.

Mean scrape time for four parsers. astral-html took the least time on the Wikipedia, PyPI, and GitHub pages.

Each parser reads a saved page and extracts the URLs and text of links matching a page-specific CSS selector. Bars show mean time per scrape across 12 fresh processes. Whiskers show one standard error, and each page has its own scale. Three-snapshot results · 1,867-page corpus results

Quick start

Pass the page HTML as a string, then select the links that have an href.

from astral_html import parse

html = """
<main>
    <a href="/guide">Read <b>the guide</b></a>
    <a>Draft</a>
</main>
"""
doc = parse(html)

links = []
for link in doc.select("main a[href]"):
    href = link["href"]
    links.append((href, link.text))

print(links)  # [('/guide', 'Read the guide')]

The tree follows nesting in the source. For example, in <ul><li>A<li>B</ul> the second li is a child of the first, so select("ul > li") returns one item with the text "AB".

Parsing and CSS queries · Development guide

Licensed under MIT or Apache-2.0.

Metadata

Release files for astral-html 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for astral-html 0.0.1
File Size Uploaded Provenance Actions
astral_html-0.0.1.tar.gz 161.6 kB Without provenance Details for astral_html-0.0.1.tar.gz

Release files / astral_html-0.0.1.tar.gz

Download URL astral_html-0.0.1.tar.gz
Size 161.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e5360394666d24b0f88dd11d25be58a02a94381864659d1250327b427d2ee860
BLAKE2b-256 checksum
How to use checksums
cef4a57da6f81724cd3005cc02eb3239cb62d21132e048d8802d997c0f5b4956
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for astral-html 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page