A Python utility for scraping web domains, processing the content, and generating embeddings suitable for Retrieval-Augmented Generation (RAG) systems. Features both automatic and interactive scraping modes.
This tool is designed to enhance the capabilities of Large Language Models by providing domain-specific knowledge through RAG techniques. It works by:
- Crawling and scraping pages within a specified web domain (with interactive selection option)
- Processing and cleaning the HTML content into usable text
- Generating high-quality embeddings from the processed content
- Storing these embeddings in a vector database ready for RAG applications
Think of it as building a specialized knowledge library that LLMs can reference when answering questions about specific domains.
Using pip:
pip install rag-scraperUsing uv (recommended):
uv pip install rag-scraperFor development:
git clone https://github.com/yourusername/rag-scraper.git
cd rag-scraper
uv pip install -e ".[dev]"Automatically crawls and scrapes an entire domain:
# Using the package
rag-scraper --domain example.com --output-dir ./data
# Using the module directly
python cli-module.py --domain example.com --output-dir ./dataDiscovers pages and lets you interactively select which ones to scrape:
# Using the package
rag-scraper --domain example.com --output-dir ./data --interactive
# Using the interactive script directly
python interactive-test.py --domain example.com --output-dir ./data --max-pages 100In interactive mode, you'll be presented with a list of discovered pages and options to:
- Select all pages
- Select specific pages by index (e.g., 1,3,5-7)
- Filter pages by keyword
- Select none (cancel operation)
If you've already scraped content and just want to process and embed it:
python process-embed.py --domain example.com --input-dir ./data/html --output-dir ./data| Option | Description | Default |
|---|---|---|
--domain |
Domain to scrape (required) | None |
--output-dir |
Directory to save output files | ./data |
--max-pages |
Maximum number of pages to scrape | 1000 |
--respect-robots |
Respect robots.txt file | True |
--log-level |
Logging level (DEBUG, INFO, WARNING, ERROR) | INFO |
--interactive |
Enable interactive page selection | False |
You can also create a .env file based on the provided .env.example to configure your scraping parameters and API keys.
rag-scraper/
├── cli-module.py # Main command-line interface
├── config-module.py # Configuration management
├── interactive-scraper-module.py # Interactive scraping functionality
├── scraper-module.py # Standard web scraper
├── processor-module.py # Content processing
├── embeddings-module.py # Embedding generation
├── storage-module.py # Vector storage
├── interactive-test.py # Standalone interactive scraper script
└── process-embed.py # Standalone processing script
- Interactive Page Selection: Browse and select specific pages to scrape
- Two Scraping Modes:
- Standard mode for comprehensive crawling
- Interactive mode for selective scraping
- Respects robots.txt and site crawling policies
- Intelligent rate limiting to avoid overloading servers
- Content deduplication
- Customizable content processors
- Support for multiple embedding models
- Optional separate processing pipeline for pre-scraped content
The system works like a library cataloging service:
-
Discovery and Collection:
- Standard Mode: Like a librarian collecting all books from a specific publisher
- Interactive Mode: Like a librarian carefully selecting specific titles from a publisher's catalog
-
Processing: Converting raw HTML into clean, usable text chunks with appropriate metadata
-
Embedding Generation: Creating semantic vector representations that capture the meaning of each text chunk
-
Vector Storage: Organizing these embeddings in a searchable database for quick retrieval
When an LLM needs to answer a domain-specific question, it can quickly retrieve and reference the most relevant content.
# Scrape a domain and process the content
python cli-module.py --domain docs.example.com --output-dir ./data# Discover and interactively select pages
python interactive-test.py --domain docs.example.com --output-dir ./data --max-pages 50
# Process the scraped HTML files
python process-embed.py --domain docs.example.com --input-dir ./data/html --output-dir ./dataContributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.