森林海
def __init__(self, crawler): self.crawler = crawler @classmethod def from_crawler(cls, crawler): return cls(crawler) # 结束爬虫 self.crawler.engine.close_spider(spider, 'closespider')上面是实现原理,实际上 scrapy.Spider 已经拥有了 crawler 属性,不必再像上面这样写。在spider中可直接写:1self.crawler.engine.close_spider(self, 'closespider')在 pipeline 和 中间件Middlewares 中:1spider.crawler.engine.close_spider(spider, 'closespider')