我无法在解析方法中更改蜘蛛设置。但这绝对是一种方式。
例如:
类SomeSpider(BaseSpider):
名称 = '我的蜘蛛'
allowed_domains = ['example.com']
start_urls = ['http://example.com']
settings.overrides['ITEM_PIPELINES'] = ['myproject.pipelines.FirstPipeline']
打印设置['ITEM_PIPELINES'][0]
#printed 'myproject.pipelines.FirstPipeline'
def 解析(自我,响应):
#...一些代码
settings.overrides['ITEM_PIPELINES'] = ['myproject.pipelines.SecondPipeline']
打印设置['ITEM_PIPELINES'][0]
# 打印'myproject.pipelines.SecondPipeline'
项目 = Myitem()
item['mame'] = 'SecondPipeline 的名称'
但!项目将由 FirstPipeline 处理。新的 ITEM_PIPELINES 参数不起作用。开始抓取后如何更改设置?提前致谢!