Skip to main content

markdown_webscraper

Scrape websites with botasaurus, save raw .html, then convert .html and .pdf to .md with markitdown.

API Reference

Core Classes

markdown_webscraper.WebsiteScraper

The main class for running the scraping process.

Constructor: WebsiteScraper(config: ScraperConfig, fetcher: PageFetcher | None = None, sleeper: Callable[[float], None] = time.sleep)

  • config: A ScraperConfig object containing scraping parameters.
  • fetcher: An optional implementation of PageFetcher. Defaults to BotasaurusFetcher.
  • sleeper: A function to handle time delays. Defaults to time.sleep.

Methods:

  • run() -> CrawlStats: Starts the scraping process based on the provided configuration. Returns CrawlStats containing the results.

markdown_webscraper.ScraperConfig

A dataclass representing the scraper configuration.

Attributes:

  • raw_html_dir (Path): Directory to save raw HTML files.
  • markdown_dir (Path): Directory to save converted Markdown files.
  • wildcard_websites (list[str]): List of root URLs for recursive scraping.
  • individual_websites (list[str]): List of specific URLs to scrape.
  • remove_header_footer (bool): Whether to prune <header> and <footer> tags.
  • markdown_convert (bool): Whether to convert HTML to Markdown.
  • time_delay (float): Delay between requests in seconds.
  • total_timeout (float): Maximum time in seconds for the entire scraping process.

markdown_webscraper.CrawlStats

A dataclass containing statistics from a completed crawl.

Attributes:

  • pages_fetched (int): Total number of pages requested.
  • html_files_saved (int): Total number of HTML files written to disk.
  • markdown_files_saved (int): Total number of Markdown files written to disk.

Utilities

markdown_webscraper.load_config(config_path: str | Path) -> ScraperConfig

Loads a ScraperConfig from a JSON file.


Usage Example

from pathlib import Path
from markdown_webscraper import WebsiteScraper, load_config

# Load configuration from a JSON file
config = load_config("config.json")

# Initialize and run the scraper
scraper = WebsiteScraper(config=config)
stats = scraper.run()

print(f"Scraped {stats.pages_fetched} pages.")
print(f"Saved {stats.markdown_files_saved} markdown files.")

Local Development

python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt

Run with local script:

python scrape.py --config config.json

Run as installed package CLI:

markdown-webscraper --config config.json

Configuration

The CLI expects a JSON config file:

{
  "raw_html_dir": "/home/brosnan/markdown_webscraper/raw_html/",
  "markdown_dir": "/home/brosnan/markdown_webscraper/markdown/",
  "wildcard_websites": ["https://www.allaboutcircuits.com/textbook", ""],
  "individual_websites": ["https://example.com/", "https://www.ti.com/lit/ds/sprs590g/sprs590g.pdf"],
  "remove_header_footer": true,
  "markdown_convert": true,
  "time_delay": 2,
  "total_timeout": 180
}

Tests

pytest tests/unit -q

Integration example.com:

RUN_INTEGRATION=1 pytest tests/integration/test_live_scrape.py::test_integration_example_com -m integration -q

Integration allaboutcircuits textbook:

RUN_INTEGRATION=1 RUN_FULL_TEXTBOOK_INTEGRATION=1 pytest tests/integration/test_live_scrape.py::test_integration_allaboutcircuits_textbook_recursive -m integration -q

Build and Publish to PyPI

  1. Update version in pyproject.toml.
  2. Build distributions:
python -m pip install --upgrade build twine
python -m build
  1. Check artifacts:
python -m twine check dist/*
  1. Upload:
python -m twine upload dist/*

Metadata

Release files for markdown-webscraper 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for markdown-webscraper 0.1.4
File Size Uploaded Provenance Actions
markdown_webscraper-0.1.4.tar.gz 7.7 kB Without provenance Details for markdown_webscraper-0.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for markdown-webscraper 0.1.4
File Interpreter ABI Platform Actions
markdown_webscraper-0.1.4-py3-none-any.whl Python 3 none any Details for markdown_webscraper-0.1.4-py3-none-any.whl

Total release size: 16.9 kB

Release files / markdown_webscraper-0.1.4.tar.gz

Download URL markdown_webscraper-0.1.4.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3911738947fa6d8b2f2f99144eda5a5e5c5fcac36a7fdbdc555ede89555d59ad
BLAKE2b-256 checksum
How to use checksums
4f25ec4a9ec83cd02ef67104a15ba5b6825b9736d9cb92234cd67244b0506054
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / markdown_webscraper-0.1.4-py3-none-any.whl

Download URL markdown_webscraper-0.1.4-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
91e0df3a9cf4abeccafeacfae393b9b4a0d661324cef2a8292dd0e5c23a728ed
BLAKE2b-256 checksum
How to use checksums
ded945a347fdf6231774bb9b011b6dacb1985b7c39ec5ec1c67fd55abfc73345
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Security for markdown-webscraper 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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