A powerful FastAPI-based web scraping service that bypasses anti-bot measures using multiple scraping backends including BrightData CDP and Camoufox browser automation.
- Multiple Scraping Backends: Support for BrightData CDP and Camoufox scrapers
- Anti-Bot Bypass: Advanced techniques to bypass bot detection systems
- API Authentication: Secure Bearer token authentication (optional)
- Proxy Support: Built-in proxy authentication and rotation
- Human-like Behavior: Simulates natural mouse movements and scrolling
- Retry Logic: Automatic retry with exponential backoff
- Health Monitoring: Built-in health checks and monitoring endpoints
- Docker Ready: Fully containerized with Docker and Docker Compose
- Security Focused: Runs with non-root user and security profiles
- RESTful API: Clean REST API with comprehensive documentation
anti-bot-bypass-server/
βββ app/
β βββ main.py # FastAPI application entry point
β βββ config.py # Configuration management
β βββ models.py # Pydantic data models
β βββ constants/
β β βββ app_data.py # Application constants
β βββ services/
β βββ base.py # Abstract scraper interface
β βββ factory.py # Scraper factory pattern
β βββ brightdata.py # BrightData CDP scraper
β βββ camoufox_scraper.py # Camoufox scraper
βββ Dockerfile # Docker container configuration
βββ docker-compose.yml # Docker Compose orchestration
βββ seccomp_profile.json # Security profile for containers
βββ pyproject.toml # Python project configuration
- Docker and Docker Compose
- BrightData CDP endpoint (for BrightData scraper)
git clone <repository-url>
cd anti-bot-bypass-serverCopy the example environment file and configure it:
cp environment.example .envThen edit the .env file with your configuration:
# Required for BrightData scraper
BRIGHTDATA_CDP_ENDPOINT=wss://your-brightdata-endpoint
# Optional configurations
API_HOST=0.0.0.0
API_PORT=8000
API_DEBUG=false
DEFAULT_TIMEOUT=30000
MAX_RETRIES=3# Build and start the service
docker-compose up --build
# Run in background
docker-compose up -d --build
# View logs
docker-compose logs -f
# Stop the service
docker-compose downCheck if the service is running:
curl http://localhost:8001/healthExpected response:
{
"status": "healthy",
"version": "0.1.0",
"available_scrapers": ["brightdata_cdp", "camoufox"]
}- Swagger UI: http://localhost:8001/docs
- ReDoc: http://localhost:8001/redoc
GET /healthGET /scrapersPOST /scrape
Content-Type: application/json
Authorization: Bearer your_api_key_here
{
"url": "https://example.com",
"scraper_type": "camoufox",
"selector_to_wait_for": "h1.title",
"timeout": 30000,
"headless": true,
"headers": {
"User-Agent": "Custom User Agent"
},
"cookies": {
"session": "abc123"
},
"proxy_server": "proxy.example.com:8080",
"proxy_username": "username",
"proxy_password": "password",
"proxy_url": "http://proxy.example.com:8080"
}Note: The Authorization header is only required if authentication is enabled (see configuration section).
| Variable | Description | Default | Required |
|---|---|---|---|
API_HOST |
API server host | 0.0.0.0 |
No |
API_PORT |
API server port | 8000 |
No |
API_DEBUG |
Enable debug mode | false |
No |
BRIGHTDATA_CDP_ENDPOINT |
BrightData CDP endpoint | - | Yes* |
DEFAULT_TIMEOUT |
Default request timeout (ms) | 30000 |
No |
MAX_RETRIES |
Maximum retry attempts | 3 |
No |
ENABLE_AUTH |
Enable API key authentication | false |
No |
API_KEY |
API key for authentication | - | Yes** |
PLAYWRIGHT_BROWSERS_PATH |
Browser installation path | /tmp/playwright |
No |
XDG_CACHE_HOME |
Cache directory path | /app/cache |
No |
*Required only if using BrightData scraper
**Required only if ENABLE_AUTH=true
brightdata_cdp: Uses BrightData's CDP endpoint for scrapingcamoufox: Uses Camoufox browser with stealth capabilities
- Install PDM (Python Dependency Manager):
pip install pdm- Install Dependencies:
pdm install- Run Development Server:
pdm run devapp/main.py: FastAPI application with lifecycle managementapp/config.py: Pydantic settings for configuration managementapp/models.py: Request/response models and enumsapp/services/: Scraper implementations following factory patternapp/constants/: Application constants and metadata
- Create a new scraper class inheriting from
BaseScraper - Implement required methods:
scrape(),initialize(),cleanup(),name - Register the scraper in
ScraperFactory - Add the scraper type to
ScraperTypeenum
The Dockerfile supports the following build arguments:
PLAYWRIGHT_VERSION: Playwright Docker image version (default:v1.55.0-noble)
- API Authentication: Optional Bearer token authentication
- Security profiles: Configurable security restrictions
- Resource limits: Memory and CPU constraints
- Network isolation: Custom Docker network
- Shared memory: 2GB shared memory for browser processes
- Browser cache: Persistent volume for browser data
- Tmpfs mounts: In-memory temporary storage
- Optional API key authentication
- Configurable security profiles
- Minimal attack surface with specific capability grants
- Resource limits to prevent DoS
- Custom Docker network isolation
- Health check endpoints for monitoring
- Configurable timeouts and rate limiting
The service includes comprehensive health checks:
- Container health: Docker health check every 30s
- Application health:
/healthendpoint - Scraper availability: Lists available scrapers
- Structured logging with different levels
- Container logs accessible via Docker Compose
- Persistent log storage in
./logsdirectory
# View real-time logs
docker-compose logs -f anti-bot-bypass-server
# View logs for specific timeframe
docker-compose logs --since="1h" anti-bot-bypass-server# Check if BRIGHTDATA_CDP_ENDPOINT is set
docker-compose exec anti-bot-bypass-server env | grep BRIGHTDATA
# Test connectivity (without auth)
curl -X POST http://localhost:8001/scrape \
-H "Content-Type: application/json" \
-d '{"url": "https://httpbin.org/ip", "scraper_type": "brightdata_cdp"}'
# Test connectivity (with auth)
curl -X POST http://localhost:8001/scrape \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your_api_key_here" \
-d '{"url": "https://httpbin.org/ip", "scraper_type": "brightdata_cdp"}'# Check browser dependencies
docker-compose exec anti-bot-bypass-server playwright install-deps
# Check container logs for errors
docker-compose logs anti-bot-bypass-server# Increase shared memory
# Edit docker-compose.yml: shm_size: 4gb
# Monitor memory usage
docker stats anti-bot-bypass-serverEnable debug logging by setting environment variable:
API_DEBUG=true- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- FastAPI - Modern, fast web framework
- Playwright - Browser automation library
- Camoufox - Stealth browser automation
- BrightData - Proxy and data collection platform
For support, please open an issue on GitHub or contact the maintainers.
Made with β€οΈ by Nirav Joshi