Skip to main content
Proper error handling is crucial for building reliable scrapers. Scrapling provides multiple layers of error handling from automatic retries to custom error callbacks.

Fetcher-Level Error Handling

Automatic Retries

All fetchers automatically retry failed requests:
Configuration: scrapling/engines/_browsers/_validators.py:88-89

Try-Catch Pattern

Handle exceptions manually:

Proxy Errors

Detect and handle proxy-related errors:
Proxy error indicators:
Source: scrapling/engines/toolbelt/proxy_rotation.py:7-15, 27-30

Spider Error Handling

On Error Hook

Handle errors at the spider level:
Source: scrapling/spiders/spider.py:178-184

Graceful Degradation

Extract partial data even when errors occur:

Error Statistics

Track error rates:

Logging Configuration

Custom Log Levels

Source: scrapling/spiders/spider.py:87-89

Log to File

Source: scrapling/spiders/spider.py:90, 118-122

Log Counting

Track log message counts:
Source: scrapling/spiders/spider.py:21-56, 110-112

Session Errors

Session Not Started

Context Manager Closed

Source: scrapling/engines/_browsers/_stealth.py:212-213

Session Configuration Errors

Source: scrapling/spiders/spider.py:59-62, 130-137

Validation Errors

Invalid Arguments

Type Validation

Source: scrapling/fetchers/stealth_chrome.py:54-55

Proxy Validation

Source: scrapling/engines/toolbelt/proxy_rotation.py:64-84

Timeout Handling

Request Timeouts

Page Pool Timeouts

Source: scrapling/engines/_browsers/_base.py:275-283

Complete Error Handling Example

Best Practices

Always use context managers for sessions:
Comprehensive logging helps debugging:
Monitor error rates to detect issues:
Extract partial data when possible:

Handling Blocked Requests

Detect and retry blocked requests

Performance Optimization

Optimize retry strategies

Anti-Bot Bypass

Avoid errors with better stealth

Cloudflare Turnstile

Handle Cloudflare challenges