【问题标题】:Python Scrapy , how to define a pipeline for an item?Python Scrapy,如何为项目定义管道?
【发布时间】:2010-11-06 14:22:08
【问题描述】:

我正在使用scrapy爬取不同的站点,每个站点我都有一个Item(提取的信息不同)

好吧,例如我有一个通用管道(大部分信息是相同的)但现在我正在抓取一些谷歌搜索响应并且管道必须不同。

例如:

GenericItem 使用GenericPipeline

但是GoogleItem 使用GoogleItemPipeline,但是当蜘蛛爬行时它会尝试使用GenericPipeline 而不是GoogleItemPipeline....如何指定Google 蜘蛛必须使用哪个管道?

【问题讨论】:

    标签: python screen-scraping scrapy


    【解决方案1】:

    现在只有一种方法 - 检查管道中的项目类型并处理它或“按原样”返回

    pipelines.py:

    from grabbers.items import FeedItem
    
    class StoreFeedPost(object):
    
        def process_item(self, domain, item):
            if isinstance(item, FeedItem):
                #process it...
    
            return item
    

    items.py:

    from scrapy.item import ScrapedItem
    
    class FeedItem(ScrapedItem):
        pass
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多