scrapy同一个爬虫里包含不同item,pipelines文件编写

pipelines文件编写

首先应该导入items文件里的不同的item类

from NcepuSpider.items import ArticleViewsCountItem
from NcepuSpider.items import ArticleBodyItem
from NcepuSpider.items import NcepuNewsSpiderItem
然后通过if判断方式进行items类别筛选

def process_item(self, item, spider):
    # 写入json文件
    if isinstance(item, ArticleViewsCountItem):
        print 1
    elif isinstance(item, ArticleBodyItem):
        print 2
    elif isinstance(item, NcepuNewsSpiderItem):
        print 3
    return item
关键字isinstance

items文件类:

class NcepuNewsSpiderItem(scrapy.Item):

class ArticleBodyItem(scrapy.Item):
class ArticleViewsCountItem(scrapy.Item):

你可能感兴趣的:(scrapy同一个爬虫里包含不同item,pipelines文件编写)