Skip to main content

A tool to fetch webpages and convert their content to clean Markdown format for LLM processing

Project description

MDScraper

A specialized tool for extracting clean, structured content from webpages and converting it to Markdown format. Ideal for preparing web content for LLM embeddings and semantic search applications.

Features

  • Clean and normalize web content for optimal LLM processing
  • Extract relevant content while filtering out noise, navigation, ads, and irrelevant elements
  • Transform HTML content into consistent, well-structured Markdown format
  • Process single URLs or batch process multiple URLs from a file
  • Intelligent content detection for various webpage layouts
  • Options to ignore images and links to reduce token usage in embeddings
  • Option to add extra spacing before headings for improved document structure
  • Debug mode for troubleshooting extraction issues

Installation

Option 1: Install from PyPI

uv pip install mdscraper

Option 2: Install from source

First, ensure you have UV installed. If not, install it following the official UV installation guide:

curl -LsSf https://astral.sh/uv/install.sh | sh

Then clone and install the repository:

git clone https://github.com/yourusername/mdscraper.git
cd mdscraper
uv pip install .

Usage

Process a single URL

mdscraper --url https://example.com --output example.md

Process multiple URLs from a file

Create a text file with one URL per line, then run:

mdscraper --file urls.txt --outdir output_directory

Using as a library

MDScraper can also be imported and used programmatically:

from mdscraper import fetch_content

# Fetch content as markdown (default)
markdown_content = fetch_content("https://example.com")


# Additional options
content = fetch_content(
    "https://example.com",
    ignore_images=True,  # Remove images
    ignore_links=True,   # Remove links
    debug=True,          # Enable debug output
    extra_heading_space="2"  # Add extra newlines before headings
    prepend_source_link=True # Prepend source link
)

Additional options

  • --debug or -d: Enable debug mode for more information
  • --no-images: Ignore all images in the content
  • --no-links: Ignore all links in the content
  • --extra-heading-space LEVELS: Add newlines before specific heading levels for better readability. LEVELS can be:
    • all: Add spacing to all heading levels (h1-h6)
    • 1,2,3: Comma-separated list of specific heading levels to apply spacing to
  • --prepend-source-link: Prepend source link in content

Development

Running Tests

To run the test suite, first ensure you have the development dependencies installed:

uv pip install -e ".[dev]"

Then run the tests:

# Run tests without coverage
pytest tests/

# Run tests with coverage report
pytest tests/ --cov

The coverage report will show you which parts of the code are covered by tests and which lines are missing coverage.

License

MIT

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

mdscraper-0.1.3.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

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

mdscraper-0.1.3-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file mdscraper-0.1.3.tar.gz.

File metadata

  • Download URL: mdscraper-0.1.3.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for mdscraper-0.1.3.tar.gz
Algorithm Hash digest
SHA256 cba398fce6e0d0e9f6dc9042be07425cdc0655c3c186326e075fa9869a2333ec
MD5 e8dfb1fe42cd2b84f64d475098cff89d
BLAKE2b-256 ca928c451897daef28876f04d21eddcb671f1935342c5baba49dff42c80143ec

See more details on using hashes here.

File details

Details for the file mdscraper-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: mdscraper-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for mdscraper-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b1c83ace317b63736218bb1cd9aa96256a2a05f742c24e45bad912087ff5f2ea
MD5 5549d256b862a9992f062b5919418ecd
BLAKE2b-256 c9a5a759cee48e74cc4fcc4649d68ef04ef1d330443bfdfecb5bb983821d83f6

See more details on using hashes here.

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