Skip to main content

Fetch a web page and convert it into cleaned Markdown.

Project description

extract2md

extract2md is all about “HTML in → Markdown out.” You can start from a live URL, a file on disk, or an already-loaded HTML string.

It can be used from CLI or as a Python library.

Installation

pip install extract2md

Prerequisites:

  • Python 3.10+ runtime
  • Node.js (recommended for best results; powers Readability.js content extraction)

CLI usage

1. Fetch a URL and display Markdown

extract2md https://www.iana.org/help/example-domains

2. Fetch and write to a file

extract2md --output sample-output.md https://www.iana.org/help/example-domains

3. Convert previously saved HTML (files or stdin)

# convert file
extract2md sample-page.html
# or from stdin
cat sample-page.html | extract2md -

4. Skip Markdown conversion and emit the HTML verbatim

extract2md --raw https://example.com

Parameters

  • source: URL, filesystem path, or - to read HTML from stdin.
  • -o/--output PATH: optional destination file (stdout is the default).
  • --raw: bypass HTML-to-Markdown conversion and emit the response body.
  • --user-agent STRING: override the default identifier.
  • --ignore-robots: skip robots.txt validation (use sparingly).
  • --proxy URL: HTTP(S) proxy forwarded to httpx.
  • --timeout SECONDS: request timeout (default 30 seconds).
  • --rewrite-relative-urls/--no-rewrite-relative-urls:
    enable or disable rewriting relative href/src attributes to absolute links (default on).
  • --base-url URL: optional base URL for rewriting relative urls (default source).

Python Library usage

extract2md can also be used as a Python library.

1. Fetch a URL and get Markdown

from extract2md import fetch_to_markdown

markdown = fetch_to_markdown("https://www.iana.org/help/example-domains")

2. Convert a previously saved HTML file

from extract2md import file_to_markdown

markdown_from_file = file_to_markdown("sample-page.html")

3. Convert an HTML string you already have

from extract2md import html_to_markdown

html = "<html><body><h1>Offline HTML</h1></body></html>"
markdown_from_html = html_to_markdown(html)

# Optionally disable replacing relative links with absolute URLs
markdown_custom = html_to_markdown(
    html,
    rewrite_relative_urls=False,
)

# Or replace relative links with a custom base URL
markdown_custom = html_to_markdown(
    html,
    rewrite_relative_urls=False,
    base_url="https://example.com/docs/",
)

Additional public methods

Need to store markup or run your own converter? Use fetch and skip the Markdown step entirely:

from extract2md import fetch

raw_html, content_type = fetch("https://example.com/docs")

Notes

  • The CLI and library both fetch live webpages from URLs; network availability and site rate limits apply.
  • Set the EXTRACT2MD_NODE_PATH environment variable to the Node.js binary (or its directory) if Readability.js cannot find node on your PATH.
  • Inspired by the Fetch MCP Server.
  • Thanks go to these libraries for the heavy lifting:

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

extract2md-0.1.1.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

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

extract2md-0.1.1-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file extract2md-0.1.1.tar.gz.

File metadata

  • Download URL: extract2md-0.1.1.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for extract2md-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b34a464517aea0d06e8d080274d9e42f1bda99fc9ce08606cdfa2dc1f9daae75
MD5 b6022fc23dca503d3f9779b4af9b4a44
BLAKE2b-256 c1ea22dcb4d3b5315ba3671d8ba1f5c810d28b12e5b5d7097d07ac7edf8b1eab

See more details on using hashes here.

Provenance

The following attestation bundles were made for extract2md-0.1.1.tar.gz:

Publisher: ci.yml on Wuodan/extract2md

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

File details

Details for the file extract2md-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: extract2md-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for extract2md-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6f94755ab471c008ec733092ed6ed5ff96a28b1d3f46b3d74ee278fc1ee48039
MD5 6d997432e9ceae436b1295d910ea31b1
BLAKE2b-256 b6cd3c471b626650bb1fd9868d2b27cacf0424655220052fa887a9be56ed0b46

See more details on using hashes here.

Provenance

The following attestation bundles were made for extract2md-0.1.1-py3-none-any.whl:

Publisher: ci.yml on Wuodan/extract2md

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