Skip to main content

daz-web-extract

Async Python library that extracts clean title and body text from any URL. It automatically escalates through multiple fetch strategies to handle everything from simple static pages to JavaScript-rendered content. It never throws exceptions — every call returns a structured result indicating success or failure.

Installation

Requires Python 3.12+.

pip install daz-web-extract

After installing, set up the browser engine for pages that require JavaScript rendering:

playwright install chromium

Usage

Python API

The library exposes a single async function extract and a result type ExtractionResult.

import asyncio
from daz_web_extract import extract, ExtractionResult

result: ExtractionResult = asyncio.run(extract("https://example.com"))

if result.success:
    print(result.title)           # Page title
    print(result.body)            # Clean body text
    print(result.fetch_method)    # Which strategy succeeded
    print(result.content_length)  # Length of body in characters
    print(result.elapsed_ms)      # Total time in milliseconds
    print(result.status_code)     # HTTP status code (if available)
else:
    print(result.error)           # Human-readable error message

Fetch Strategy

Four tiers escalate automatically until one succeeds:

Tier Method Description
1 httpx Fast async HTTP fetch with lxml extraction (10s timeout)
2 trafilatura Thread-based extraction via trafilatura (15s timeout)
3 playwright-nojs Headless browser with JS disabled — fast SSR extraction
4 playwright Headless browser with JS enabled — full rendering for SPAs (30s timeout)

Tier 3 detects "requires javascript" phrases in the extracted content and automatically escalates to tier 4 when JavaScript is needed. HTTP 4xx/5xx responses (except 403/429) skip tier 2 and go straight to tier 3.

Limiting fetch strategies

Use the max_tier parameter to control how far the library escalates:

# Only use fast HTTP fetch (no browser, no trafilatura)
result = await extract("https://example.com", max_tier=1)

# Use HTTP fetch + trafilatura, but skip the browser
result = await extract("https://example.com", max_tier=2)

# Use HTTP fetch + trafilatura + browser without JS
result = await extract("https://example.com", max_tier=3)

# Use all strategies including full JS browser (default)
result = await extract("https://example.com", max_tier=4)

Serialization

Results can be converted to dictionaries or JSON:

result.to_dict()  # Returns a plain dict
result.to_json()  # Returns a JSON string

Using in async code

import asyncio
from daz_web_extract import extract

async def main():
    urls = [
        "https://example.com",
        "https://www.iana.org/help/example-domains",
    ]
    results = await asyncio.gather(*[extract(url) for url in urls])
    for r in results:
        print(f"{r.url}: {r.title} ({r.content_length} chars)")

asyncio.run(main())

Command Line

Extract content from a URL via the run script:

./run extract https://example.com

Output:

Title: Example Domain
Method: httpx
Length: 217 chars
Time: 142ms

Example Domain
This domain is for use in illustrative examples in documents. You may use this
domain in literature without prior coordination or asking for permission.
More information...

Get raw JSON output:

./run extract https://example.com --raw

Other commands:

# Run tests
./run test src/daz_web_extract/result_test.py

# Run linter
./run lint

# Run full quality checks
./run check

Development

Set up a development environment:

python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
playwright install chromium

Run the tests:

pytest -q src/

Metadata

Release files for daz-web-extract 0.4.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 daz-web-extract 0.4.1
File Size Uploaded
daz_web_extract-0.4.1.tar.gz 28.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for daz-web-extract 0.4.1
File Interpreter ABI Platform
daz_web_extract-0.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 60.9 kB

Release files / daz_web_extract-0.4.1.tar.gz

Download URL daz_web_extract-0.4.1.tar.gz
Size 28.8 kB
Tags Source
SHA-256 checksum
How to use checksums
21dd7cda6af49e78b60ce2497b1c91db00a77f5ffce51c0352a22f02dfbb6e23
BLAKE2b-256 checksum
How to use checksums
90c094d8ede903ea620adab5508a4a8b9e7677ef8f0f2ceb4cbe2fb7371dd982
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / daz_web_extract-0.4.1-py3-none-any.whl

Download URL daz_web_extract-0.4.1-py3-none-any.whl
Size 32.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
940d990ec11fcc564bbf9533100a6756988b338b06c5a3544e074f94f0b36abc
BLAKE2b-256 checksum
How to use checksums
46765b19329a2680758956e3e9df7917c6dd986afdcfaaa62bbd3a68bd7f7843
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files

0.4.0

2 release files

0.2.0

2 release files

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