Scrapy信号量

1、类

from scrapy import signals


class MySingle(object):
    def __init__(self):
        pass

    @classmethod
    def from_crawler(cls, crawler):
        self = cls()

        crawler.signals.connect(self.spider_open, signal=signals.spider_opened)
        crawler.signals.connect(self.spider_close, signal=signals.spider_closed)

        return self

    def spider_open(self, spider):
        print('打开')

    def spider_close(self, spider):
        print('关闭')

2、配置文件

EXTENSIONS = {
   # 'scrapy.extensions.telnet.TelnetConsole': None,
   'toscrapy.mysingles.MySingle': 555,
}

 

posted @ 2019-10-28 23:24  市丸银  阅读(238)  评论(0编辑  收藏  举报