代码之家  ›  专栏  ›  技术社区  ›  Jan

刮擦自定义设置

  •  2
  • Jan  · 技术社区  · 6 年前

    scrapy ,我的一个蜘蛛里有:

    class IndexSpider(scrapy.Spider):
        name = "indices"
    
        def __init__(self, *args, **kwargs):
            super(IndexSpider, self).__init__(*args, **kwargs)
    
            # set custom settings
            custom_settings = {
                'DOWNLOAD_DELAY': 2,
                'ITEM_PIPELINES': {
                    'freedom.pipelines.IndexPipeline': 300
                }
            }
    

    但是,当我稍后尝试通过

        print(dict(self.settings.get('ITEM_PIPELINES')))
    


    我做错什么了?

    1 回复  |  直到 6 年前
        1
  •  7
  •   Valdir Stumm Junior    6 年前

    custom_settings 应该是类属性:

    class IndexSpider(scrapy.Spider):
        name = "indices"
    
        # set custom settings
        custom_settings = {
            'DOWNLOAD_DELAY': 2,
            'ITEM_PIPELINES': {
                'freedom.pipelines.IndexPipeline': 300
            }
        }
    
        def __init__(self, *args, **kwargs):
            super(IndexSpider, self).__init__(*args, **kwargs)