Skip to main content
The Response class extends Selector to provide a unified response type across different fetching engines. It includes HTTP metadata alongside all the parsing capabilities of Selector.

Constructor

str
required
The URL of the response
str | bytes
required
The response content (automatically converted to bytes)
int
required
HTTP status code (e.g., 200, 404, 500)
str
required
HTTP status reason phrase (e.g., “OK”, “Not Found”)
Tuple[Dict[str, str], ...] | Dict[str, str]
required
Response cookies
Dict
required
Response headers
Dict
required
Request headers that were sent
str
default:"utf-8"
Character encoding to use for parsing
str
default:"GET"
HTTP method used (GET, POST, etc.)
List
default:"None"
List of redirect responses if any
Dict[str, Any]
default:"None"
Additional metadata dictionary. Must be a dict if provided
Any
Additional configuration passed to the Selector base class (e.g., adaptive, huge_tree, keep_comments, etc.)

Properties

status

HTTP status code of the response. Example:

reason

HTTP status reason phrase. Example:

cookies

Response cookies. Example:

headers

Response headers. Example:

request_headers

Headers that were sent with the request. Example:

history

List of redirect responses if the request was redirected. Example:

meta

Additional metadata dictionary. Useful for passing custom data between requests in spiders. Example:

request

Reference to the Request object that generated this response. Set by the crawler. Example:

body

Return the raw body of the response as bytes. Returns: The response body as bytes Example:

Methods

follow()

Create a Request to follow a URL. This is a helper method for spiders to easily follow links found in pages. IMPORTANT: Most arguments, if left empty, will use the corresponding value from the previous request. The only exception is dont_filter.
str
required
The URL to follow (can be relative, will be joined with current URL)
str
default:""
The session id to use. Defaults to the original request’s session id
Callable
default:"None"
Spider callback method to use. Defaults to the original request’s callback
int
default:"None"
The priority number to use, the higher the number, the higher priority to be processed first. Defaults to the original request’s priority
bool
default:"false"
If this request has been done before, disable the filter to allow it again
dict[str, Any]
default:"None"
Additional meta data to include in the request. Will be merged with the current response’s meta
bool
default:"true"
Set the current response URL as referer for the new request URL
Any
Additional Request arguments. Will be merged with the original session kwargs
Returns: A Request object ready to be yielded Example:

String Representation

__str__()

String representation of the response. Returns: A string in the format <status url> Example:

Inheritance

Since Response inherits from Selector, all Selector methods and properties are available: Selection Methods:
  • css() - Select with CSS selectors
  • xpath() - Select with XPath
  • find(), find_all() - Find by various filters
  • find_by_text() - Find by text content
  • find_by_regex() - Find by regex pattern
Properties:
  • text - Element text content
  • attrib - Element attributes
  • html_content - Inner HTML
  • tag - Tag name
  • parent, children, siblings - DOM navigation
Extraction:
  • get(), getall() - Serialize elements
  • get_all_text() - Get all text content
  • json() - Parse JSON
  • re(), re_first() - Extract with regex
See the Selector documentation for complete details.

Example Usage