关于scrapy crawl命令首个参数及教程中quotes参数的技术疑问
Hey there! Let's break down your questions about Scrapy's crawl command clearly:
scrapy crawl The first parameter you pass to scrapy crawl is the spider's name—this is the unique identifier Scrapy uses to locate and run the exact spider you want.
Every Scrapy spider you write must have a name attribute defined in its class. For example, if you have a spider class like this:
import scrapy class MySpider(scrapy.Spider): name = "my_cool_spider" # ... rest of your spider logic
You'd launch it with scrapy crawl my_cool_spider. Scrapy relies on this name to tell multiple spiders in your project apart—so each spider's name has to be unique, otherwise you'll run into conflicts when trying to trigger a crawl.
quotes (in scrapy crawl quotes) and quotes_spider.py The quotes argument directly maps to the name attribute of the spider class inside your quotes_spider.py file.
When following the Scrapy tutorial, you likely defined a class in quotes_spider.py that looks something like this:
import scrapy class QuotesSpider(scrapy.Spider): name = "quotes" start_urls = [ 'https://quotes.toscrape.com/', ] # ... parse method and other crawl logic
Scrapy automatically scans all .py files in your project's spiders directory for classes that inherit from scrapy.Spider. When you run scrapy crawl quotes, it sifts through those scanned spiders, finds the one with name = "quotes", and executes that spider's crawl workflow.
As a quick side note: The filename (quotes_spider.py) doesn't have a strict technical tie to the spider's name—you could name the file random_name.py and still have a spider with name = "quotes" inside it. But naming the file to match the spider's name is a widely used convention to keep your project organized, making it easy to tell which file contains which spider at a glance.
内容的提问来源于stack exchange,提问作者Terrence Brannon

