Skip to main content

Convert web pages to markdown

Project description

Webdown

Python Tests codecov PyPI version Python Versions License: MIT

A Python CLI tool for converting web pages to clean, readable Markdown format. Webdown makes it easy to download documentation and feed it into an LLM coding tool.

Why Webdown?

  • Clean Conversion: Produces readable Markdown without formatting artifacts
  • Selective Extraction: Target specific page sections with CSS selectors
  • Claude XML Format: Optimized output format for Anthropic's Claude AI models
  • Progress Tracking: Visual download progress for large pages with -p flag
  • Optimized Handling: Automatic streaming for large pages (>10MB) with no configuration required

Use Cases

Documentation for AI Coding Assistants

Webdown is particularly useful for preparing documentation to use with AI-assisted coding tools like Claude Code, GitHub Copilot, or ChatGPT:

  • Convert technical documentation into clean Markdown for AI context
  • Extract only the relevant parts of large documentation pages using CSS selectors
  • Strip out images and formatting that might consume token context
  • Generate well-structured tables of contents for better navigation
# Example: Convert API docs and store for AI coding context
webdown https://api.example.com/docs -s "main" -I -c -w 80 -o api_context.md

Installation

From PyPI

pip install webdown

Install from Source

# Clone the repository
git clone https://github.com/kelp/webdown.git
cd webdown

# Install with pip
pip install .

# Or install with Poetry
poetry install

Usage

Basic usage:

webdown https://example.com/page.html -o output.md

Output to stdout:

webdown https://example.com/page.html

Options

  • -o, --output: Output file (default: stdout)
  • -t, --toc: Generate table of contents
  • -L, --no-links: Strip hyperlinks
  • -I, --no-images: Exclude images
  • -s, --css SELECTOR: CSS selector to extract specific content
  • -c, --compact: Remove excessive blank lines from the output
  • -w, --width N: Set the line width for wrapped text (0 for no wrapping)
  • -p, --progress: Show download progress bar (useful for large files)
  • --claude-xml: Output in Claude XML format for use with Claude AI
  • --no-metadata: Exclude metadata section from Claude XML output (metadata is included by default)
  • --no-date: Exclude current date from metadata in Claude XML output (date is included by default)

For more details on the Claude XML format, see the Anthropic documentation on Claude XML.

For large web pages (over 10MB), streaming mode is automatically used to optimize memory usage without any configuration required.

Examples

Generate markdown with a table of contents:

webdown https://example.com -t -o output.md

Extract only main content:

webdown https://example.com -s "main" -o output.md

Strip links and images:

webdown https://example.com -L -I -o output.md

Compact output with progress bar and line wrapping:

webdown https://example.com -c -p -w 80 -o output.md

Generate Claude XML format for use with Claude AI:

webdown https://example.com --claude-xml -o doc.xml

Claude XML with no metadata section:

webdown https://example.com --claude-xml --no-metadata -o doc.xml

Claude XML without the current date in metadata:

webdown https://example.com --claude-xml --no-date -o doc.xml

For complete documentation, use the --help flag:

webdown --help

Documentation

API documentation is available online at tcole.net/webdown.

You can also generate the documentation locally with:

make docs        # Generate HTML docs in the docs/ directory
make docs-serve  # Start a local documentation server at http://localhost:8080

Development

Prerequisites

  • Python 3.10+ (3.13 recommended)
  • Poetry for dependency management

Setup

# Clone the repository
git clone https://github.com/kelp/webdown.git
cd webdown

# Install dependencies with Poetry
poetry install
poetry run pre-commit install

# Optional: Start a Poetry shell for interactive development
poetry shell

Development Commands

We use a Makefile to streamline development tasks:

# Install dependencies
make install

# Run tests
make test

# Run tests with coverage
make test-coverage

# Run integration tests
make integration-test

# Run linting
make lint

# Run type checking
make type-check

# Format code
make format

# Run all pre-commit hooks
make pre-commit

# Run all checks (lint, type-check, test)
make all-checks

# Build package
make build

# Start interactive Poetry shell
make shell

# Generate documentation
make docs

# Start documentation server
make docs-serve

# Publishing to PyPI (maintainers only)
# See CONTRIBUTING.md for details on the release process
make build         # Build package
make publish-test  # Publish to TestPyPI (for testing)

# Show all available commands
make help

Poetry Commands

You can also use Poetry directly:

# Start an interactive shell in the Poetry environment
poetry shell

# Run a command in the Poetry environment
poetry run pytest

# Add a new dependency
poetry add requests

# Add a development dependency
poetry add --group dev black

# Update dependencies
poetry update

# Build package
poetry build

Python API Usage

Webdown can also be used as a Python library in your own projects:

from webdown.converter import convert_url_to_markdown, WebdownConfig

# Basic conversion
markdown = convert_url_to_markdown("https://example.com")

# Using the Config object for more options
config = WebdownConfig(
    url="https://example.com",
    include_toc=True,
    css_selector="main",
    compact_output=True,
    body_width=80,
    show_progress=True
)
markdown = convert_url_to_markdown(config)

# Save to file
with open("output.md", "w") as f:
    f.write(markdown)

# Convert to Claude XML format (optimized for Anthropic's Claude AI)
from webdown.converter import convert_url_to_claude_xml, ClaudeXMLConfig

# Basic Claude XML conversion
xml = convert_url_to_claude_xml("https://example.com")

# With custom XML configuration
claude_config = ClaudeXMLConfig(
    include_metadata=True,   # Include title, URL, and date (default: True)
    add_date=True,           # Include current date in metadata (default: True)
    doc_tag="claude_documentation"  # Root document tag name (default)
)
xml = convert_url_to_claude_xml("https://example.com", claude_config)

# Save XML output
with open("output.xml", "w") as f:
    f.write(xml)

# For more information on Claude XML format, see:
# https://docs.anthropic.com/claude/docs/advanced-data-extraction

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Run tests to make sure everything works:
    # Run standard tests
    poetry run pytest
    
    # Run tests with coverage
    poetry run pytest --cov=webdown
    
    # Run integration tests
    poetry run pytest --integration
    
  4. Commit your changes (git commit -m 'Add some amazing feature')
  5. Push to the branch (git push origin feature/amazing-feature)
  6. Open a Pull Request

Please make sure your code passes all tests, type checks, and follows our coding style (enforced by pre-commit hooks). We aim to maintain high code coverage (currently at 93%). When adding features, please include tests.

For more details, see our Contributing Guide.

Support

If you encounter any problems or have feature requests, please open an issue on GitHub.

License

MIT License - see the LICENSE file for details.

Project details


Download files

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

Source Distribution

webdown-0.5.0.tar.gz (28.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

webdown-0.5.0-py3-none-any.whl (31.1 kB view details)

Uploaded Python 3

File details

Details for the file webdown-0.5.0.tar.gz.

File metadata

  • Download URL: webdown-0.5.0.tar.gz
  • Upload date:
  • Size: 28.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for webdown-0.5.0.tar.gz
Algorithm Hash digest
SHA256 759a95fe559689722c63c5d411d52252d525def3138425642b2b68671cee8b95
MD5 0e52893b848acbf2f9c02b2601eefd33
BLAKE2b-256 ae891c6f22277b8dc299754be280e2526a96bdbfcd040ca6fcc8ad67fbf11fc9

See more details on using hashes here.

Provenance

The following attestation bundles were made for webdown-0.5.0.tar.gz:

Publisher: python-release.yml on kelp/webdown

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file webdown-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: webdown-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 31.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for webdown-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2d2e4d41f4267b64bbf23f8a119e54f90396921d3bb9c2a0af224986d646fcf9
MD5 78eabca39a6404c070335e92eb41dc3c
BLAKE2b-256 d70c8e507270fbb3dcf1948f5f06161c4af9a44ef35ba5d645d72c2e9242d623

See more details on using hashes here.

Provenance

The following attestation bundles were made for webdown-0.5.0-py3-none-any.whl:

Publisher: python-release.yml on kelp/webdown

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page