Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

What are the request and response objects in scrapy?


Asked by Everly Chavez on Dec 11, 2021 FAQ



Scrapy can crawl websites using the Request and Response objects. The request objects pass over the system, uses the spiders to execute the request and get back to the request when it returns a response object. The request object is a HTTP request that generates a response. It has the following class −
Likewise,
Scrapy schedules the scrapy.Request objects returned by the start_requests method of the Spider. Upon receiving a response for each one, it instantiates Response objects and calls the callback method associated with the request (in this case, the parse method) passing the response as argument.
Similarly, Scrapy schedules the scrapy.Request objects returned by the start_requests method of the Spider. Upon receiving a response for each one, it instantiates Response objects and calls the callback method associated with the request (in this case, the parse method) passing the response as argument. A shortcut to the start_requests method ¶
Accordingly,
process_exception () should return: either None, a Response object, or a Request object. If it returns None, Scrapy will continue processing this exception, executing any other process_exception () methods of installed middleware, until no middleware is left and the default exception handling kicks in.
Thereof,
Scrapy calls process_exception () when a download handler or a process_request () (from a downloader middleware) raises an exception (including an IgnoreRequest exception) process_exception () should return: either None, a Response object, or a Request object.