美文网首页
自定义扩展

自定义扩展

作者: lkning | 来源:发表于2018-01-13 22:35 被阅读0次

    自定义扩展时,利用信号在指定位置注册制定操作

    from scrapy import signals
    
    
    class MyExtension(object):
        def __init__(self, value):
            self.value = value
    
        @classmethod
        def from_crawler(cls, crawler):
            val = crawler.settings.getint('MMMM')
            ext = cls(val)
    
            crawler.signals.connect(ext.spider_opened, signal=signals.spider_opened)
            crawler.signals.connect(ext.spider_closed, signal=signals.spider_closed)
    
            return ext
    
        def spider_opened(self, spider):
            print('open')
    
        def spider_closed(self, spider):
            print('close')
    

    相关文章

      网友评论

          本文标题:自定义扩展

          本文链接:https://www.haomeiwen.com/subject/gluhoxtx.html