Skip to main content

Overview

Sessions in Scrapling provide persistent connections, cookie management, and state preservation across multiple requests. They’re essential for efficient scraping and authenticated workflows.

HTTP Sessions

Connection pooling for HTTP requests

Browser Sessions

Persistent browser contexts

State Management

Cookies, headers, and configuration

Why Use Sessions?

Without Sessions

With Sessions

HTTP Sessions (FetcherSession)

The FetcherSession provides persistent HTTP connections using curl_cffi.

Basic Usage

Configuration

Set default options for all requests in the session:

Override Per Request

Request-specific parameters override session defaults:

HTTP Methods

Persistent Configuration

Browser Sessions

Browser sessions maintain persistent browser contexts for multiple page loads.

DynamicSession

Persistent browser context for standard automation:

Configuration Options

Page Pooling

Browser sessions use page pooling for better performance:

Browser Automation in Sessions

StealthySession

Stealth browser session with anti-detection:

Async Browser Sessions

Asynchronous browser automation:

Proxy Rotation with Sessions

Automatic proxy rotation on request failures:

Proxy Rotation with Browser Sessions

Session Comparison

FetcherSession

Best for:
  • Static sites
  • APIs
  • Fast scraping
  • High volume
Speed: Very FastOverhead: Minimal

DynamicSession

Best for:
  • JavaScript sites
  • SPAs
  • Automation
  • Complex interactions
Speed: MediumOverhead: Browser process

StealthySession

Best for:
  • Bot detection
  • Cloudflare
  • Protected sites
  • Production scraping
Speed: Medium-SlowOverhead: Browser + stealth

Advanced Patterns

Login and Scrape Pattern

Multi-Step Browser Workflow

Session Retry Logic

Session State Management

Saving Browser State

Sharing Configuration

Error Handling

Best Practices

Always Use Context Managers

Reuse Sessions

Configure Once

Implementation Details

FetcherSession Internals

Browser Session Internals

Next Steps

Fetchers

Learn about fetcher types

Parsing

Extract data from responses

Examples

Real-world session examples