Item extraction
Extract structured fields from HTML or other downloaded content.
Scrapy · Function
parse is a Scrapy spider’s default callback for processing responses without an explicitly assigned callback. It extracts items and can yield requests to continue crawling.
Define parse on a spider to handle a downloaded Response, extract data, and optionally produce more requests. Scrapy uses it by default when a request has no callback, including the requests generated from start URLs; callback keyword arguments supplied through cb_kwargs are also accepted.
parse(response: Response, **kwargs: Any) -> Any| Name | Type | Description |
|---|---|---|
response | Response | The downloaded response to process and extract data from. |
**kwargs | Any | Additional keyword arguments supplied through the request’s cb_kwargs. |
A Request, item, iterable of requests and/or items, or None.
import scrapy
class QuotesSpider(scrapy.Spider):
name = "quotes"
start_urls = ["https://quotes.toscrape.com/"]
def parse(self, response):
for quote in response.css(".quote"):
yield {
"text": quote.css(".text::text").get(),
"author": quote.css(".author::text").get(),
}
The spider’s default callback extracts fields from each matching element and yields one item per quote.
Extract structured fields from HTML or other downloaded content.
Follow pagination, detail links, or discovered URLs.
Propagate request-specific context into callback processing.
parse is the default callback for responses whose requests do not specify a callback. It receives the Response, extracts data, and can return or yield items and further requests.
Follow-up: What happens to requests yielded by parse? Scrapy schedules them, downloads their responses, and invokes the callback assigned to each request.
Its first argument is the Response being processed. It may also receive keyword arguments passed through the request’s cb_kwargs.
Follow-up: How can a callback remain compatible with arbitrary callback data? Accept keyword parameters, typically through **kwargs, in addition to response.
parse may produce a Request, an item, an iterable containing requests or items, or None. Yielding is commonly used to emit multiple results incrementally.
Follow-up: Why yield rather than build a list? Yielding lets Scrapy consume results incrementally and avoids requiring all outputs to be held at once.
scrapy.SpiderResponseRequeststart()start_urlscb_kwargscallbackSelectors