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.2.tar.gz (15.5 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.2-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mdscraper-0.1.2.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.10

File hashes

Hashes for mdscraper-0.1.2.tar.gz
Algorithm Hash digest
SHA256 30d75ab7ee0483bdf78a465ca1c3fe3e5122030eef51540731376671ee95aaee
MD5 423f854f7b555906b9c2aae079c76817
BLAKE2b-256 0f24ea3a0208a48ec292ab5a352ef87caec2935458b198454aab8fe61c48376c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mdscraper-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.10

File hashes

Hashes for mdscraper-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1c1b538a4ef10c0ad4d67e4d0f37da6fbb8f04fc2ac0575b968efd93aca8e332
MD5 e046c32aa228124c69784b87258988bf
BLAKE2b-256 b68b85162336c218eb28ad46c41ff355eb1a8629ae4fbc178fec9cc3816b3cc7

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