【问题标题】:Scrapy - Different pipeline per ItemScrapy - 每个项目不同的管道
【发布时间】:2021-08-10 18:39:23
【问题描述】:

我是 Scrapy 和 python 的新手,请原谅我对此一无所知。

我需要在数据库中存储两种不同类型的项目。对于其中之一,我需要在插入之前做一些额外的查询。是否可以根据项目有不同的管道?如果不是,当它们到达管道时,我如何区分哪个项目是哪个?

【问题讨论】:

    标签: python scrapy


    【解决方案1】:

    基本上,您可以丢弃您不想在某些管道中处理的项目,反之亦然。例如:

    class ApplePipeLine(object):
    
        def process_item(self, item, spider):
            if not isinstance(item, Apple):
                return item
            # Do something with Apple
            return item
    
    
    class OrangePipeLine(object):
    
        def process_item(self, item, spider):
            if not isinstance(item, Orange):
                return item
            # Do something with Orange
            return item
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-12
      • 2012-01-12
      • 1970-01-01
      • 1970-01-01
      • 2018-11-01
      相关资源
      最近更新 更多