scrapy: Call a function when a spider quits

后端 未结 6 1164
猫巷女王i
猫巷女王i 2020-11-27 14:29

Is there a way to trigger a method in a Spider class just before it terminates?

I can terminate the spider myself, like this:

class MySpider(CrawlS         


        
6条回答
  •  心在旅途
    2020-11-27 15:20

    For the latest version(v1.7), just define closed(reason) method in your spider class.

    closed(reason):

    Called when the spider closes. This method provides a shortcut to signals.connect() for the spider_closed signal.

    Scrapy Doc : scrapy.spiders.Spider.closed

提交回复
热议问题