A high-performance, production-ready search engine scraping system with multi-engine support, automatic fallback, and advanced anti-detection capabilities.
- Google - Multiple fallback strategies (direct, mobile, browser, library)
- DuckDuckGo - Uses native library (fastest, most reliable)
- Bing - Full anti-detection support
- Yahoo - Complete search support
- 50+ requests/minute throughput
- < 2 second response time (average)
- Concurrent batch processing
- Connection pooling
- Async/await architecture
- Fingerprint Randomization - Browser fingerprints rotate automatically
- User-Agent Rotation - Realistic browser signatures
- Proxy Rotation - Auto-fetch and rotate proxies
- TLS Fingerprint Variation - Randomized SSL/TLS settings
- Request Header Randomization - Sec-CH-UA, Accept headers, etc.
- Stealth Browser Mode - Playwright/Selenium with anti-detection scripts
- Auto-fetch free proxies from 5+ public sources
- Support for HTTP, HTTPS, SOCKS4, SOCKS5
- Automatic health checking and rotation
- Custom proxy support via environment variables
- reCAPTCHA v2 (audio challenge)
- reCAPTCHA v3 (behavior simulation)
- Cloudflare Turnstile bypass
- Image captcha OCR (Tesseract + EasyOCR)
- hCaptcha support
When one search engine fails, automatically tries the next:
Google → DuckDuckGo → Bing → Yahoo
- Web search
- News search
- Image search
- Video search
# Clone the repository
git clone <repository-url>
cd search-scraper
# Copy environment file
cp .env.example .env
# Start the services
docker-compose up -d
# Check health
curl http://localhost:8000/health# Create virtual environment
python -m venv venv
source venv/bin/activate # Linux/Mac
# or: venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt
# Install Playwright browsers
playwright install chromium
# Run the server
python -m uvicorn app.main:app --reload --host 0.0.0.0 --port 8000The unified endpoint automatically handles fallback between search engines:
curl -X POST http://localhost:8000/api/v1/search/unified \
-H "Content-Type: application/json" \
-d '{
"query": "python web scraping",
"num_results": 10,
"search_type": "all",
"enable_fallback": true
}'curl -X POST http://localhost:8000/api/v1/search/google \
-H "Content-Type: application/json" \
-d '{
"query": "machine learning",
"num_results": 10,
"search_type": "all"
}'curl -X POST http://localhost:8000/api/v1/search/duckduckgo \
-H "Content-Type: application/json" \
-d '{
"query": "artificial intelligence",
"num_results": 10
}'curl -X POST http://localhost:8000/api/v1/search/bing \
-H "Content-Type: application/json" \
-d '{
"query": "data science",
"num_results": 10
}'curl -X POST http://localhost:8000/api/v1/search/yahoo \
-H "Content-Type: application/json" \
-d '{
"query": "web development",
"num_results": 10
}'curl -X POST http://localhost:8000/api/v1/search/batch \
-H "Content-Type: application/json" \
-d '{
"queries": ["python", "javascript", "rust", "go"],
"num_results": 10,
"engine": "auto"
}'curl -X POST http://localhost:8000/api/v1/search/all-engines \
-H "Content-Type: application/json" \
-d '{
"query": "cloud computing",
"num_results": 10
}'curl -X POST http://localhost:8000/api/v1/search/unified \
-H "Content-Type: application/json" \
-d '{
"query": "technology news",
"search_type": "news",
"num_results": 20
}'curl -X POST http://localhost:8000/api/v1/search/unified \
-H "Content-Type: application/json" \
-d '{
"query": "nature wallpaper",
"search_type": "images",
"num_results": 20
}'curl http://localhost:8000/api/v1/search/instant/python%20programming| Variable | Default | Description |
|---|---|---|
API_HOST |
0.0.0.0 |
API host address |
API_PORT |
8000 |
API port |
API_WORKERS |
4 |
Number of worker processes |
DEBUG |
False |
Enable debug mode |
MAX_SEARCH_REQUESTS_PER_MINUTE |
120 |
Rate limit for searches |
MAX_CONCURRENT_REQUESTS |
100 |
Max concurrent connections |
USE_PROXY |
True |
Enable proxy rotation |
AUTO_FETCH_PROXIES |
True |
Auto-fetch free proxies |
CUSTOM_PROXIES |
`` | Comma-separated custom proxies |
ENABLE_CAPTCHA_SOLVER |
True |
Enable captcha solving |
ENABLE_FALLBACK |
True |
Enable search engine fallback |
FALLBACK_ORDER |
google,duckduckgo,bing,yahoo |
Fallback order |
REQUEST_TIMEOUT |
15 |
Request timeout in seconds |
PAGE_LOAD_TIMEOUT |
15 |
Browser page load timeout |
Add your own proxies via environment variable:
CUSTOM_PROXIES=http://proxy1:8080,socks5://user:pass@proxy2:1080,http://proxy3:3128Supported formats:
http://host:porthttps://host:portsocks4://host:portsocks5://host:portsocks5://user:pass@host:port
┌─────────────────────────────────────────────────────────────┐
│ FastAPI Application │
├─────────────────────────────────────────────────────────────┤
│ Unified Search Engine │
│ ┌─────────┐ ┌─────────────┐ ┌──────┐ ┌───────┐ │
│ │ Google │ │ DuckDuckGo │ │ Bing │ │ Yahoo │ │
│ └────┬────┘ └──────┬──────┘ └──┬───┘ └───┬───┘ │
│ └──────────────┴──────────┴─────────┘ │
│ ▼ │
│ ┌─────────────────────┐ │
│ │ Request Handler │ │
│ │ (6+ strategies) │ │
│ └──────────┬──────────┘ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Anti-Detection Layer │ │
│ │ • Fingerprint Randomization • TLS Variation │ │
│ │ • User-Agent Rotation • Header Randomization │ │
│ │ • Proxy Rotation • Stealth Browser │ │
│ └─────────────────────────────────────────────────────┘ │
│ ▼ │
│ ┌────────────────┐ ┌────────────────┐ ┌──────────────┐ │
│ │ Proxy Manager │ │ Captcha Solver │ │ Rate Limiter │ │
│ │ (auto-fetch) │ │ (multi-type) │ │ (token bucket)│ │
│ └────────────────┘ └────────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────┘
├── app/
│ ├── __init__.py
│ ├── main.py # FastAPI application
│ ├── api/
│ │ ├── __init__.py
│ │ ├── search_scraper.py # Search API endpoints
│ │ └── website_scraper.py # Website scraping endpoints
│ ├── config/
│ │ ├── __init__.py
│ │ └── settings.py # Configuration management
│ ├── core/
│ │ ├── __init__.py
│ │ ├── captcha_solver.py # Captcha detection & solving
│ │ ├── proxy_manager.py # Proxy fetching & rotation
│ │ ├── rate_limiter.py # Rate limiting
│ │ └── request_handler.py # Request handling with anti-detection
│ ├── scrapers/
│ │ ├── __init__.py
│ │ ├── google_scraper.py # Google search scraper
│ │ ├── duckduckgo_scraper.py # DuckDuckGo scraper
│ │ ├── bing_scraper.py # Bing search scraper
│ │ ├── yahoo_scraper.py # Yahoo search scraper
│ │ └── generic_scraper.py # Generic website scraper
│ ├── parsers/
│ │ ├── __init__.py
│ │ ├── contact_extractor.py
│ │ └── content_parser.py
│ └── utils/
│ ├── __init__.py
│ ├── helpers.py
│ └── user_agents.py
├── config/
│ ├── config.yaml
│ ├── proxies.txt # HTTP proxies (optional)
│ └── socks_proxies.txt # SOCKS proxies (optional)
├── logs/
├── docker-compose.yml
├── Dockerfile
├── requirements.txt
├── .env.example
└── README.md
import asyncio
from app.scrapers import GoogleScraper, DuckDuckGoScraper, BingScraper, YahooScraper
async def main():
# Initialize scrapers
google = GoogleScraper()
ddg = DuckDuckGoScraper()
bing = BingScraper()
yahoo = YahooScraper()
# Google search with fallback
result = await google.search(
query="python web scraping",
num_results=10,
search_type="all",
fast_mode=True
)
if result['success']:
for item in result['results']:
print(f"{item['title']}: {item['url']}")
# DuckDuckGo (fastest)
result = await ddg.search(
query="machine learning",
num_results=20
)
# Batch search
queries = ["python", "javascript", "rust"]
tasks = [ddg.search(q, num_results=5) for q in queries]
results = await asyncio.gather(*tasks)
asyncio.run(main())from app.core.proxy_manager import proxy_manager
# Add custom proxies at runtime
proxy_manager._add_proxy("http://myproxy:8080", source="custom")
proxy_manager._add_proxy("socks5://user:pass@socks.example.com:1080", source="custom")# Build and start
docker-compose up -d --build
# View logs
docker-compose logs -f api
# Stop services
docker-compose down
# Start with development mode
docker-compose --profile dev up -d
# Start with nginx (production)
docker-compose --profile production up -d
# Rebuild without cache
docker-compose build --no-cache| Endpoint | Method | Description |
|---|---|---|
/ |
GET | API information |
/health |
GET | Health check |
/status |
GET | Detailed status |
/proxy-stats |
GET | Proxy statistics |
/api/v1/search/unified |
POST | Unified search with fallback |
/api/v1/search/all-engines |
POST | Search all engines concurrently |
/api/v1/search/google |
POST | Google search |
/api/v1/search/duckduckgo |
POST | DuckDuckGo search |
/api/v1/search/bing |
POST | Bing search |
/api/v1/search/yahoo |
POST | Yahoo search |
/api/v1/search/batch |
POST | Batch search |
/api/v1/search/instant/{query} |
GET | DuckDuckGo instant answer |
/docs |
GET | Swagger UI documentation |
/redoc |
GET | ReDoc documentation |
- Never expose the API directly to the internet without authentication
- Use a reverse proxy (nginx) with rate limiting in production
- Monitor proxy health and rotate frequently
- Be respectful of search engines' terms of service
- Implement proper error handling and logging
- Use DuckDuckGo for speed - It uses a native library, no scraping needed
- Enable fast_mode - Reduces pages fetched per search
- Use batch endpoint - For multiple queries
- Configure proper timeouts - Lower values = faster failures
- Monitor proxy health - Remove slow/dead proxies
- Use Redis - For distributed rate limiting
1. Brotli encoding error
pip install Brotli brotlicffi2. Playwright not working
playwright install chromium
playwright install-deps chromium3. No results from Google
- Google is heavily blocked; use unified search with fallback
- DuckDuckGo is most reliable
4. Slow response times
- Enable proxy rotation
- Use fast_mode=true
- Reduce num_results
5. Captcha detected
- System will attempt to solve automatically
- Try different search engine
- Use more proxies
MIT License - See LICENSE file for details.
Contributions are welcome! Please read the contributing guidelines first.
For issues and feature requests, please use the GitHub issue tracker.