Ethical web scraper with robots.txt compliance, AI-powered interpretation, and comprehensive content extraction
Project description
RespectScraper
An ethical Python web scraping library that prioritizes robots.txt compliance, features AI-powered interpretation of ambiguous rules, and provides comprehensive content extraction capabilities.
🚀 Features
- Robots.txt Compliance: Automatically checks and respects robots.txt files with intelligent parsing
- AI-Powered Interpretation: Uses configurable LLM providers (OpenAI, Anthropic, Custom) to interpret ambiguous robots.txt files
- Nested Link Crawling: Crawls nested links with configurable depth limits and domain restrictions
- Comprehensive File Extraction: Downloads and extracts content from PDFs, Excel files, Word documents, and text files
- Respectful Rate Limiting: Built-in rate limiting to prevent overwhelming target servers
- API Integration: Configurable API endpoints to seamlessly send scraped data
- Flexible Configuration: JSON-based configuration for all settings and behaviors
- Command Line Interface: Intuitive CLI for common scraping tasks
- Ethical Override Options: Support for user-owned sites and brute force mode with clear disclaimers
📦 Installation
From PyPI (when published)
pip install respectscraper
From Source
git clone https://github.com/Zakhele-TechWannabe/respectscraper.git
cd respectscraper
pip install -e .
Dependencies
The package requires Python 3.8+ and the following libraries:
- requests
- beautifulsoup4
- lxml
- PyPDF2
- openpyxl
- python-docx
- openai (optional, for LLM features)
- anthropic (optional, for LLM features)
- ratelimit
- aiohttp
- aiofiles
🎯 Quick Start
1. Create Configuration
respectscraper config --create
2. Basic Scraping
from webscraper import WebScraper
scraper = WebScraper('config.json')
result = scraper.scrape_url('https://example.com')
print(result)
scraper.close()
3. Command Line Usage
# Basic scraping
respectscraper scrape https://example.com
# With nested links and file extraction
respectscraper scrape https://example.com --nested --download
# Ignore robots.txt (use responsibly)
respectscraper scrape https://example.com --brute-force
# Save results to file
respectscraper scrape https://example.com --output results.json --pretty
⚙️ Configuration
The scraper uses a JSON configuration file. Create a default one with:
respectscraper config --create
Key Configuration Sections
General Settings
{
"general": {
"user_agent": "AdvancedWebScraper/1.0 (Respectful Bot)",
"timeout": 30,
"max_retries": 3,
"respect_robots_txt": true,
"brute_force": false,
"allow_user_override": true
}
}
LLM Integration (for robots.txt interpretation)
{
"llm": {
"provider": "openai",
"model": "gpt-3.5-turbo",
"api_key": "your-api-key-here",
"max_tokens": 500,
"temperature": 0.1
}
}
API Integration
{
"api": {
"enabled": true,
"endpoint": "https://your-api-endpoint.com/data",
"method": "POST",
"headers": {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY"
}
}
}
📖 Usage Examples
Basic Website Scraping
from webscraper import WebScraper
scraper = WebScraper('config.json')
result = scraper.scrape_url('https://example.com')
if result['success']:
data = result['data']
print(f"Title: {data['title']}")
print(f"Content: {data['text_content'][:500]}...")
else:
print(f"Failed: {result['reason']}")
scraper.close()
Nested Link Crawling
result = scraper.scrape_url(
'https://example.com',
nested=True # Enable nested crawling
)
if result['success'] and 'nested_pages' in result['data']:
for page in result['data']['nested_pages']:
print(f"Found page: {page['url']}")
if page['success']:
print(f" Title: {page['data']['title']}")
File Extraction
result = scraper.scrape_url(
'https://example.com/documents',
download=True # Enable file downloading
)
if result['success'] and 'extracted_files' in result['data']:
for file_data in result['data']['extracted_files']:
print(f"Extracted: {file_data['url']}")
print(f"Type: {file_data['data']['file_type']}")
print(f"Content: {file_data['data']['content'][:200]}...")
Handling Robots.txt Restrictions
# Respect robots.txt (default)
result = scraper.scrape_url('https://example.com')
# User claims site ownership (with disclaimer)
result = scraper.scrape_url('https://example.com', user_owns_site=True)
# Brute force mode (ignore robots.txt - use responsibly)
result = scraper.scrape_url('https://example.com', brute_force=True)
Quick Scraping Function
from webscraper import quick_scrape
result = quick_scrape(
url='https://example.com',
nested=True,
download=False
)
🤖 LLM Integration
The scraper can use AI to interpret ambiguous robots.txt files. Supported providers:
OpenAI
{
"llm": {
"provider": "openai",
"model": "gpt-3.5-turbo",
"api_key": "your-openai-api-key"
}
}
Anthropic Claude
{
"llm": {
"provider": "anthropic",
"model": "claude-3-sonnet-20240229",
"api_key": "your-anthropic-api-key"
}
}
Custom Provider
{
"llm": {
"provider": "custom",
"model": "your-model",
"api_key": "your-api-key",
"base_url": "https://your-llm-endpoint.com"
}
}
🔧 CLI Commands
Scraping
# Basic scraping
respectscraper scrape https://example.com
# Advanced options
respectscraper scrape https://example.com \
--nested \
--download \
--config custom_config.json \
--output results.json \
--pretty
# Ignore robots.txt
respectscraper scrape https://example.com --brute-force
# User owns site
respectscraper scrape https://example.com --user-owns-site
# Bypass SSL certificate verification (for problematic sites)
respectscraper scrape https://example.com --ssl-bypass
Configuration
# Create default config
respectscraper config --create
# Create config at custom path
respectscraper config --create --path my_config.json
# Validate existing config
respectscraper config --validate --path config.json
Validation and Info
# Validate installation
respectscraper validate
# Show package info
respectscraper info
🔒 Handling SSL Certificate Issues
Some websites have SSL certificate problems that prevent scraping. RespectScraper provides several ways to handle this:
Quick Solution (CLI)
# Bypass SSL verification for a single scrape
respectscraper scrape https://problematic-site.com --ssl-bypass
Configuration Solution
Edit your config.json:
{
"general": {
"verify_ssl": false,
"allow_ssl_bypass": true
}
}
Python API Solution
scraper = WebScraper('config.json')
# Temporarily disable SSL verification
scraper.session.verify = False
result = scraper.scrape_url('https://problematic-site.com')
⚠️ Security Warning
Disabling SSL verification reduces security. Only use this for:
- Trusted websites with known certificate issues
- Internal/development servers
- When you understand the security implications
📁 File Extraction Support
The scraper can extract content from various file types:
- PDF: Text extraction from all pages with metadata
- Excel: Cell data from all sheets with sheet names
- Word: Text and tables with document metadata
- Text: Auto-encoding detection for text files
🛡️ Ethical Usage
This tool is designed for responsible web scraping:
✅ Good Practices
- Always respect robots.txt files
- Use appropriate delays between requests
- Don't overload servers with too many concurrent requests
- Only scrape public, non-copyrighted content
- Respect terms of service
- Use the
user_owns_siteflag only for sites you actually own
❌ Don't Use For
- Scraping content behind login walls without permission
- Violating website terms of service
- Overloading servers with aggressive scraping
- Collecting personal or private data
- Copyright infringement
Robots.txt Override Options
The scraper provides override options but use them responsibly:
- User Owns Site: Use
user_owns_site=Trueonly if you actually own the website - Brute Force: Use
brute_force=Trueonly with explicit permission or for testing - Both options show disclaimers about responsible usage
🔍 API Integration
Send scraped data automatically to your API:
# Configure in config.json
{
"api": {
"enabled": true,
"endpoint": "https://your-api.com/scraped-data",
"method": "POST",
"headers": {
"Authorization": "Bearer YOUR_TOKEN"
}
}
}
The scraper will automatically send structured data:
{
"timestamp": "2024-01-01T12:00:00Z",
"data": {
"url": "https://example.com",
"title": "Example Title",
"content": "Scraped content...",
"word_count": 500,
"nested_pages": [...],
"extracted_files": [...]
}
}
🧪 Testing Installation
# Validate installation
respectscraper validate
# Test with a simple page
respectscraper scrape https://httpbin.org/html --pretty
📚 Advanced Usage
Custom User Agent
# Modify config.json
{
"general": {
"user_agent": "MyRespectfulBot/1.0 (+https://mysite.com/bot-info)"
}
}
Rate Limiting Configuration
{
"crawling": {
"delay_between_requests": 2.0, # 2 seconds between requests
"max_concurrent_requests": 3 # Max 3 concurrent requests
}
}
File Size Limits
{
"file_extraction": {
"max_file_size_mb": 100, # Don't download files larger than 100MB
"supported_extensions": [".pdf", ".xlsx", ".docx", ".txt"]
}
}
🐛 Troubleshooting
Common Issues
-
"Configuration file not found"
respectscraper config --create
-
"LLM API key not configured"
- Edit
config.jsonand add your API key in thellmsection
- Edit
-
"Robots.txt blocks scraping"
- Check the robots.txt file manually
- Use
--user-owns-siteif you own the site - Use
--brute-forceonly if you have permission
-
"SSL Certificate verification failed"
- Try with SSL bypass:
respectscraper scrape URL --ssl-bypass - Or edit config.json:
"allow_ssl_bypass": true, "verify_ssl": false - ⚠️ Warning: Only bypass SSL for trusted sites
- Try with SSL bypass:
-
"Rate limited"
- Increase
delay_between_requestsin config - Reduce
max_concurrent_requests
- Increase
-
"File extraction failed"
- Check if the file type is supported
- Verify file isn't corrupted
- Check file size limits
Debug Mode
# Enable debug logging
{
"logging": {
"level": "DEBUG",
"file": "debug.log"
}
}
🤝 Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📄 License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Why Apache 2.0? It provides better patent protection, trademark protection, and clearer legal terms for enterprise use while maintaining the same freedoms as MIT. See LICENSE_COMPARISON.md for details.
🔗 Links
⚖️ Disclaimer
This tool is provided for educational and legitimate scraping purposes. Users are responsible for ensuring their usage complies with applicable laws, regulations, and website terms of service. The developers are not responsible for any misuse of this software.
Always scrape responsibly and ethically!
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file respectscraper-0.1.2.tar.gz.
File metadata
- Download URL: respectscraper-0.1.2.tar.gz
- Upload date:
- Size: 37.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c76ecbdc1e9a888cd06f64bdd4ef5b1efbe5058cd41aa95ffa6b019f677c3c72
|
|
| MD5 |
1f3d4610e8ea388221ca58f5671e3a3e
|
|
| BLAKE2b-256 |
2068cbdbd2e3b7e3190578ae857170ad06734f649fea30993dd2af80849c79b0
|
Provenance
The following attestation bundles were made for respectscraper-0.1.2.tar.gz:
Publisher:
release.yml on Zakhele-TechWannabe/respectscraper
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
respectscraper-0.1.2.tar.gz -
Subject digest:
c76ecbdc1e9a888cd06f64bdd4ef5b1efbe5058cd41aa95ffa6b019f677c3c72 - Sigstore transparency entry: 356967500
- Sigstore integration time:
-
Permalink:
Zakhele-TechWannabe/respectscraper@fe7b74f58465e62eec9d2604fe166e0a0ccdc3ad -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/Zakhele-TechWannabe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@fe7b74f58465e62eec9d2604fe166e0a0ccdc3ad -
Trigger Event:
release
-
Statement type:
File details
Details for the file respectscraper-0.1.2-py3-none-any.whl.
File metadata
- Download URL: respectscraper-0.1.2-py3-none-any.whl
- Upload date:
- Size: 32.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e9ef1e7ba1cbe786b98237900415d5795fb81fdeab22b717d023271b90d7bbb5
|
|
| MD5 |
8cd9e7367d9e4a7579454f6e107d883e
|
|
| BLAKE2b-256 |
fdabca15888930c8118d79ad90afb35ab77856831f2ad3e792104b3106361862
|
Provenance
The following attestation bundles were made for respectscraper-0.1.2-py3-none-any.whl:
Publisher:
release.yml on Zakhele-TechWannabe/respectscraper
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
respectscraper-0.1.2-py3-none-any.whl -
Subject digest:
e9ef1e7ba1cbe786b98237900415d5795fb81fdeab22b717d023271b90d7bbb5 - Sigstore transparency entry: 356967520
- Sigstore integration time:
-
Permalink:
Zakhele-TechWannabe/respectscraper@fe7b74f58465e62eec9d2604fe166e0a0ccdc3ad -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/Zakhele-TechWannabe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@fe7b74f58465e62eec9d2604fe166e0a0ccdc3ad -
Trigger Event:
release
-
Statement type: