Seed a crawl with start_urls
A crawl begins from a fixed list of pages.
Scrapy · Class
scrapy.Spider is the base class for defining Scrapy crawlers. Configure initial URLs, parse responses, extract items, and yield requests to continue crawling.
Subclass scrapy.Spider to define a crawl. Scrapy uses the spider's initial URLs to create requests, invokes parse for each response by default, and lets callbacks yield extracted items or more requests to continue the crawl.
class scrapy.Spider(**args: Any*, ***kwargs: Any*)| Name | Type | Description |
|---|---|---|
*args, **kwargs | Any | Arguments supplied when the spider is instantiated; the documentation shows the class accepting arbitrary positional and keyword arguments. |
A spider callback can yield item objects and Request objects; start() yields initial Request objects.
import scrapy
class Spider(scrapy.Spider):
name = "quotes"
start_urls = ["https://example.com/"]
def parse(self, response):
yield {"title": response.css("title::text").get()}
This spider starts at the configured URL, parses the downloaded response, and yields an item containing the page title.
A crawl begins from a fixed list of pages.
Downloaded pages contain structured information.
Links or API pages lead to additional content.
Several related sites share crawl behavior.
A Spider is a class that defines which requests to send and how to process responses. It normally starts from start_urls, and parse handles each initial response by default.
Follow-up: How does a callback continue a crawl? It yields Request objects, whose callbacks process later responses.
Set start_urls to the initial URL strings. Scrapy's default start() creates a Request for each one and assigns parse as the callback.
Follow-up: What if startup requires generated or customized requests? Override start() and yield the required Request objects.
A callback parses the Response, commonly with Selectors, and yields item objects for extracted data. It may also yield Request objects to follow additional pages.
Follow-up: Can one callback return both? Yes; it can yield extracted items and continuation requests during the same response processing.
startstart_urlsparseRequestResponseSelectorsfrom_crawler