我的craigscrap / extension.py是这样的:
from scrapy import signals
from scrapy.exceptions import NotConfigured
class SendEmail(object):
def __init__(self):
self.frm = 'wrufesh@gmail.com'
self.to = 'a@f.com, b@g.com'
@classmethod
def from_crawler(cls, crawler):
if not crawler.settings.getbool('MYEXT_ENABLED'):
raise NotConfigured
ext = cls()
crawler.signals.connect(ext.send_mail, signal=signals.spider_closed)
return ext
def send_mail(self, spider):
spider.log("Are you getting the message?")
我的设置是这样的:
EXTENSIONS = {
'craigscrap.extension.SendEmail': 80,
}
我正在阅读文档以表示扩展。我为扩展编写了这段代码,但它似乎没有运行。正如我希望这段代码打印
"Are you getting the message?"
当蜘蛛关闭时请帮助我找到我的错误。
答案 0 :(得分:2)
我发现了自己的错误。 在settings.py中添加以下变量
MYEXT_ENABLED = True
EXTENSIONS = {
'craigscrap.extension.SendEmail': 80,
}