Request class represents a single request in Scrapling’s spider framework. It encapsulates the URL, callback, priority, metadata, and session parameters for fetching and processing web pages.
Class Definition
Constructor
str
required
The URL to request.
str
default:"\"\""
Session ID to use for this request. If empty, the spider’s default session is used.
Callable | None
default:"None"
Async generator function to process the response. If None, the spider’s
parse() method is used.int
default:"0"
Request priority. Higher values are processed first. Default is 0.
bool
default:"False"
If True, this request won’t be filtered by the duplicate filter, even if it’s already been seen.
dict[str, Any] | None
default:"None"
Arbitrary metadata dictionary to pass along with the request. Merged with response.meta.
int
default:"0"
Internal retry counter (managed automatically by the engine).
Any
Additional session-specific keyword arguments (e.g.,
headers, proxy, method, data, json). These are passed to the session’s fetch method.Attributes
str
The request URL.
str
Session ID for this request.
Callable | None
Response processing callback.
int
Request priority for scheduling.
bool
Whether to bypass duplicate filtering.
dict[str, Any]
Metadata dictionary.
str
Cached property that extracts the domain from the URL (e.g., “example.com”).
Methods
copy
update_fingerprint
self._fp after first computation.
bool
default:"False"
Include session kwargs (except data/json) in the fingerprint.
bool
default:"False"
Include request headers in the fingerprint.
bool
default:"False"
Keep URL fragments when canonicalizing the URL for fingerprinting.
The fingerprint is based on: URL (canonicalized), session ID, HTTP method, request body (data/json), and optionally headers and kwargs.
Special Methods
Comparison
Requests can be compared for priority-based sorting:Equality
Requests are equal if they have the same fingerprint:String Representation
Serialization
Requests support pickling for checkpoint/resume functionality. The callback is stored as a method name string and restored from the spider instance.Usage Examples
Basic Request
POST Request with JSON
Request with Custom Callback
Request with Metadata
Request with Different Session
Request with Proxy
Bypassing Duplicate Filter
Internal Attributes
int
Number of times this request has been retried (managed by CrawlerEngine).
dict
Dictionary of keyword arguments to pass to the session’s fetch method.
bytes | None
Cached fingerprint bytes. None until
update_fingerprint() is called.str | None
Temporary attribute used during pickling to store callback method name.
See Also
- Spider - Creating spiders that use requests
- SessionManager - Managing session IDs
- CrawlerEngine - How requests are processed
- Response - Response objects from requests