Skip to main content
Prerequisites
  1. You’ve read the Getting started page and know how to create and run a basic spider.
This page covers the Request object in detail — how to construct requests, pass data between callbacks, control priority and deduplication, and use response.follow() for link-following.

The Request Object

A Request represents a URL to be fetched. You create requests either directly or via response.follow():

Request Parameters

Here are all the arguments you can pass to Request: Any extra keyword arguments are forwarded directly to the underlying session. For example, to make a POST request:

Request Implementation

The Request class is defined in scrapling/spiders/request.py:
request.py:25-58

Response.follow()

response.follow() is the recommended way to create follow-up requests inside callbacks. It offers several advantages over constructing Request objects directly:
  • Relative URLs are resolved automatically against the current page URL
  • Referer header is set to the current page URL by default
  • Session kwargs from the original request are inherited (headers, proxy settings, etc.)
  • Callback, session ID, and priority are inherited from the original request if not specified

Response.follow() Parameters

Disabling Referer Flow

By default, response.follow() sets the Referer header to the current page URL. To disable this:

Callbacks

Callbacks are async generator methods on your spider that process responses. They must yield one of three types:
  • dict — A scraped item, added to the results
  • Request — A follow-up request, added to the queue
  • None — Silently ignored
All callback methods must be async def and use yield (not return). Even if a callback only yields items with no follow-up requests, it must still be an async generator.

Request Priority

Requests with higher priority values are processed first. This is useful when some pages are more important to be processed first before others:
When using response.follow(), the priority is inherited from the original request unless you specify a new one.

Deduplication

The spider automatically deduplicates requests based on a fingerprint computed from the URL, HTTP method, request body, and session ID. If two requests produce the same fingerprint, the second one is silently dropped.

Fingerprint Generation

The fingerprint is generated in request.py:
request.py:64-113

Allowing Duplicates

To allow duplicate requests (e.g., re-visiting a page after login), set dont_filter=True:

Fine-tuning Fingerprints

You can fine-tune what goes into the fingerprint using class attributes on your spider: For example, if you need to treat https://example.com/page#section1 and https://example.com/page#section2 as different URLs:

Request Meta

The meta dictionary lets you pass arbitrary data between callbacks. This is useful when you need context from one page to process another:
When using response.follow(), the meta from the current response is merged with the new meta you provide (new values take precedence). The spider system also automatically stores some metadata. For example, the proxy used for a request is available as response.meta["proxy"] when proxy rotation is enabled.