Reputation: 299
I want to log some data when the spider finishes working.
I make this function inside my spider.
def spider_closed(self, spider):
log.msg('The spider {0} finished working on'.format(self.name), level=log.INFO)
But this function is not getting fired.
Please note that I can log to my log anything and actually I am logging a lot of data that I can see in my log file. so the logging is working with me.
I guess that I have to dispatch a signal signals.spider_closed
but I don't know how to do that.
Upvotes: 4
Views: 696
Reputation: 473903
You should attach your method as a receiver
to the SignalManager
signal dispatcher:
from scrapy.xlib.pydispatch import dispatcher
from scrapy import signals
class MySpider(Spider):
def __init__(self, *args, **kwargs):
dispatcher.connect(self.spider_closed, signal=signals.spider_closed)
super(MySpider, self).__init__(*args, **kwargs)
def spider_closed(self, spider):
log.msg('The spider {0} finished working on'.format(self.name), level=log.INFO)
Also see relevant threads:
Upvotes: 5