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, }