A multithreaded 🕸️ web crawler that recursively crawls a website and creates a 🔽 markdown file for each page
Project description
| |
__ `__ \ _` | __| __| _` | \ \ \ / | _ \ __|
| | | ( | ( | ( | \ \ \ / | __/ |
_| _| _| \__._| \___| _| \__._| \_/\_/ _| \___| _|
---------------------------------
markdown_crawler - by @paulpierre
---------------------------------
A multithreaded 🕸️ web crawler that recursively crawls a website and creates a 🔽 markdown file for each page
https://github.com/paulpierre
https://x.com/paulpierre
📝 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.
Features include
- 🧵 Threading support for faster crawling
- ⏯️ Continue scraping where you left off
- ⏬ Set the max depth of children you wish to crawl
- ✅ Validates URLs, HTML, filepaths
- ⚙️ Configure list of valid base paths or base domains
- 🍲 Uses BeautifulSoup to parse HTML
- 🪵 Verbose logging option
- 👩💻 Ready-to-go CLI interface
🚀 Get started
If you wish to simply use it in the CLI, you can run the following command:
Install the package
pip install markdown-crawler
Execute the CLI
markdown-crawler -t 5 -d 3 -b ./markdown https://en.wikipedia.org/wiki/Morty_Smith
To run from the github repo, once you have it checked out:
pip install .
markdown-crawler -t 5 -d 3 -b ./markdown https://en.wikipedia.org/wiki/Morty_Smith
Or use the library in your own code:
from 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')
⚠️ Requirements
- Python 3.x
- BeautifulSoup4
- requests
🔍 Usage
The following arguments are supported
usage: markdown-crawler [-h] [--max-depth MAX_DEPTH] [--num-threads NUM_THREADS] [--base-path BASE_PATH] [--debug DEBUG]
[--target-content TARGET_CONTENT] [--target-links TARGET_LINKS] [--valid-paths VALID_PATHS]
[--domain-match DOMAIN_MATCH] [--base-path-match BASE_PATH_MATCH]
base-url
📝 Example
Take a look at 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 childrennum_threads
to 5. We will use 5 parallel(ish) threads to crawl the websitebase_dir
tomarkdown
. We will save the markdown files in themarkdown
directoryvalid_paths
an array of valid relative URL paths. We will only crawl pages that are in this list and base pathis_domain_match
toFalse
. We will only crawl pages that are in the same domain as the base URLis_base_match
toFalse
. We will include all URLs in the same domain, even if they don't begin with the base urlis_debug
to True. We will print out verbose logging
And when we run it we can view the progress
We can see the progress of our files in the markdown
directory locally
And we can see the contents of the HTML converted to markdown
❤️ Thanks
If you have an 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
- Give me a ⭐ on Github
⚖️ License
MIT License Copyright (c) 2023 Paul Pierre 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.
html2text credits
markdown_crawler
makes use of html2text by the late and legendary Aaron Swartz. The original source code can be found here. A modification was implemented to make it compatible with Python 3.x. It is licensed under GNU General Public License (GPL).
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
Built Distribution
File details
Details for the file markdown-crawler-0.0.7.tar.gz
.
File metadata
- Download URL: markdown-crawler-0.0.7.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ee49e0486849895935849353fefa8e603ebd3b99346a3c58d55104d33b62dba |
|
MD5 | 394fdd7f0274f64203ad4a3c47d46bf2 |
|
BLAKE2b-256 | 826269284ef9597104c5b9220de77e29ab7500ce2b9683d503d942ec2a00257d |
File details
Details for the file markdown_crawler-0.0.7-py3-none-any.whl
.
File metadata
- Download URL: markdown_crawler-0.0.7-py3-none-any.whl
- Upload date:
- Size: 17.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4a59baa1ec4c62bec1486052527bcb7dd4d418f312ee0f6da13e1c53732de43 |
|
MD5 | a970d04bd754f01ea769ffee162e86a7 |
|
BLAKE2b-256 | 3e593afad545037d5253a77ede842e9c606bf6d0ec2d9acadf70666efee7b3e2 |