蟒蛇Scrapy,如何定义的项目的管道?
-
20-08-2019 - |
题
我使用scrapy抓取不同的站点,每个站点我有一个项目(不同的信息被提取)
嗯,比如说我有一个通用的管道(大多数的信息是相同的),但我现在爬行一些谷歌搜索响应和管道必须是不同的。
例如:
GenericItem
使用GenericPipeline
但GoogleItem
使用GoogleItemPipeline
,但是当蜘蛛爬行它尝试使用GenericPipeline
代替GoogleItemPipeline
....我怎么可以指定谷歌蜘蛛必须使用的管道?
解决方案
现在只有一个办法 - 检查项类型在管道和过程它返回或“按原样”
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
不隶属于 StackOverflow