pipeline.py code
class Examplepipeline(object):
def __init__(self):
dispatcher.connect(self.spider_opened, signal=signals.spider_opened)
dispatcher.connect(self.spider_closed, signal=signals.spider_closed)
def spider_opened(self, spider):
log.msg("opened spider %s at time %s" % (spider.name,datetime.now().strftime('%H-%M-%S')))
def process_item(self, item, spider):
log.msg("Processsing item " + item['title'], level=log.DEBUG)
def spider_closed(self, spider):
log.msg("closed spider %s at %s" % (spider.name,datetime.now().strftime('%H-%M-%S')))
In the above spider code , it will display the starting time and ending time of the spider, but now after the completion of the spider, i want to receive a mail that "Scraping has been completed" from scrapy. Is it possible to do this. If possible can we write that code in spider_closed method, can anyone please share some example code on how to do this.
Have you looked into documentation:
http://doc.scrapy.org/en/latest/topics/email.html
Basic usage from documentation
Also you could implement something custom on your own. For example if you want to use gmail:
and just call it like:
My apologies for self-promotion, but I recently created yagmail: a package that strives to make it easy to send gmail messages (text, html, image etc).
This is the code you'd need to connect:
Then you use this to send emails:
What is nice is that you do not have to keep settings around as text, but you can rely on the OS' keyring for a real safe and comfortable feeling.
It could even be a one liner (that closes automatically):