cra草的自定义设置

时间:2018-09-12 11:47:12

标签: python scrapy

使用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 个答案:

答案 0 :(得分:3)

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)