Metadata-Version: 2.4
Name: simple-markdown-crawler
Version: 0.3.0
Summary: A multithreaded 🕸️ web crawler that recursively crawls a website and creates a 🔽 markdown file for each page
Author-email: Jose Maldonado <josemald89@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/yukiteruamano/simple-markdown-crawler
Project-URL: Repository, https://github.com/yukiteruamano/simple-markdown-crawler
Project-URL: Bug Tracker, https://github.com/yukiteruamano/simple-markdown-crawler/issues
Project-URL: Changelog, https://github.com/yukiteruamano/simple-markdown-crawler/releases
Keywords: crawler,web-scraper,markdown,rag,llm,beautifulsoup,html-to-markdown
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Text Processing :: Markup :: HTML
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: beautifulsoup4<5,>=4.15.0
Requires-Dist: markdownify<2,>=1.2.3
Requires-Dist: requests<3,>=2.34.2
Dynamic: license-file

```
                |                                     |             
 __ `__ \    _` |        __|   __|   _` | \ \  \   /  |   _ \   __| 
 |   |   |  (   |       (     |     (   |  \ \  \ /   |   __/  |    
_|  _|  _| \__._|      \___| _|    \__._|   \_/\_/   _| \___| _|    

---------------------------------------------
simple_markdown_crawler - by @yukiteru_amano
---------------------------------------------
A multithreaded 🕸️ web crawler that recursively crawls a website and creates a 🔽 markdown file for each page.
This project is a fork from markdown_crawler from Paul Pierre (abandoned for 2 years).
https://github.com/yukiteruamano
https://x.com/yukiteru_amano
```
<br><br>

# 📝 Overview
This is a multithreaded web crawler that crawls a website and creates markdown files for each page.
It was primarily created for large language model document parsing to simplify chunking and processing of large documents for RAG use cases.
Markdown by nature is human readable and maintains document structure while keeping a small footprint.
<br>

# ✨ Features include

> - 🧵 Threading support for faster crawling
> - ⏯️ Continue scraping where you left off
> - ⏬ Set the max depth of children you wish to crawl
> - 📄 Support for tables, images, etc.
> - ✅ Validates URLs, HTML, filepaths
> - ⚙️ Configure list of valid base paths, base domains and exclude paths
> - 🍲 Uses BeautifulSoup to parse HTML
> - 🪵 Verbose logging option
> - 👩‍💻 Ready-to-go CLI interface
<br>

# 🏗️ Use cases
- RAG (Retrieval Augmented Generation) - my primary usecase, use this to normalize large documents and chunk by header, pargraph or sentence
- LLM fine-tuning - Create a large corpus of markdown files as a first step and leverage `gpt-4o` or `mistral-small` to extract Q&A pairs
- Agent knowledge - Leverage this with [autogen](https://github.com/microsoft/autogen) for expert agents, for example if you wish to reconstruct the knowledge corpus of a videogame or movie, use this to generate the given expert corpus
- Agent / LLM tools - Use this for online RAG learning so your chatbot continues to learn. Use SERP and scrape + index top N results w/ markdown-crawler
- Knowledge database for OpenWebUI and others toosl for LLM Chats.
- And many more ..

<br><br>

# 🚀 Get started

## 🧪 Development setup

This project uses [uv](https://docs.astral.sh/uv/) for dependency management and
[ruff](https://docs.astral.sh/ruff/) for linting and formatting. Make sure you have `uv` installed.

Install dependencies (including dev tools):
```
uv sync --dev
```

Run the crawler from the repo:
```
uv run simple-markdown-crawler -t 5 -d 3 -b ./markdown https://en.wikipedia.org/wiki/Morty_Smith
```

### 🔧 Makefile

Alternatively, a `Makefile` centralizes the common workflows with `make`:

```
make install   # uv sync --dev
make check     # ruff check
make format    # ruff format
make lint      # ruff check + format
make lint-fix  # auto-fix lint + format
make test      # pytest
make build     # uv build (sdist + wheel, previa ejecución de tests)
make publish   # uv publish a PyPI (requiere UV_PUBLISH_TOKEN)
make sync      # uv lock --upgrade + uv sync --dev
make clean     # elimina dist/ y artefactos de build
make help      # muestra los targets disponibles
```

## 🎁 Install as a package

If you wish to simply use it in the CLI, you can install and run the package:

Install the package
```
pip install simple-markdown-crawler
```

Execute the CLI
```
simple-markdown-crawler -t 5 -d 3 -b ./markdown https://en.wikipedia.org/wiki/Morty_Smith
```

Or use the library in your own code:
```
from simple_markdown_crawler import md_crawl
url = 'https://en.wikipedia.org/wiki/Morty_Smith'
md_crawl(url, max_depth=3, num_threads=5, base_path='markdown')
```
<br><br>

# ⚠️  Requirements
- Python 3.10+
- [uv](https://docs.astral.sh/uv/) for development
- BeautifulSoup4
- requests
- markdownify

<br><br>
# 🔍 Usage

The following arguments are supported
```
usage: simple-markdown-crawler [-h] [--max-depth MAX_DEPTH]
                               [--num-threads NUM_THREADS]
                               [--base-dir BASE_DIR] [--debug]
                               [--target-content TARGET_CONTENT]
                               [--target-links TARGET_LINKS]
                               [--valid-paths VALID_PATHS]
                               [--exclude-paths EXCLUDE_PATHS]
                               [--domain-match | --no-domain-match | -m]
                               [--base-path-match | --no-base-path-match | -p]
                               [--links]
                               base_url
```

<br><br>

# 📝 Example
Take a look at [example.py](https://github.com/yukiteruamano/simple-markdown-crawler/blob/main/example.py) for an example
implementation of the library. In this configuration we set:
- `max_depth` to 3. We will crawl the base URL and 3 levels of children
- `num_threads` to 5. We will use 5 parallel(ish) threads to crawl the website
- `base_dir` to `markdown`. We will save the markdown files in the `markdown` directory
- `valid_paths` an array of valid relative URL paths. We will only crawl pages that are in this list and base path
- `exclude_paths` an array of exclude relative URL paths.
- `target_content` to `div#content`. We will only crawl pages that have this HTML element using CSS target selectors. You can provide multiple and it will concatenate the results
- `is_domain_match` to `False`. We will only crawl pages that are in the same domain as the base URL
- `is_base_path_match` to `False`. We will include all URLs in the same domain, even if they don't begin with the base url
- `is_debug` to True. We will print out verbose logging
<br><br>

And when we run it we can view the progress
<br>
> ![cli](https://github.com/yukiteruamano/simple-markdown-crawler/blob/main/img/ss_crawler.png?raw=true)

We can see the progress of our files in the `markdown` directory locally
> ![md](https://github.com/yukiteruamano/simple-markdown-crawler/blob/main/img/ss_dir.png?raw=true)

And we can see the contents of the HTML converted to markdown
> ![md](https://github.com/yukiteruamano/simple-markdown-crawler/blob/main/img/ss_markdown.png?raw=true)

<br><br>
# ❤️ Thanks 
If you have any issues, please feel free to open an issue or submit a PR. You can reach me via DM on Twitter/X.

  - Follow me on [Twitter / X](https://x.com/yukiteru_amano)
  - Give me a ⭐ on [Github](https://github.com/yukiteruamano)


<br><br>
# ⚖️ License
MIT License
Copyright (c) 2023 Paul Pierre
Copyright (c) 2025 Jose Maldonado
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

<br><br>

###  markdownify credits
`simple_markdown_crawler` makes use of markdownify by Matthew Tretter. The original source code can be found [here](https://github.com/matthewwithanm/python-markdownify). It is licensed under the [MIT license](https://github.com/matthewwithanm/python-markdownify/blob/develop/LICENSE).
