调用JsonItemPipline类
from scrapy.exporters import JsonItemExporter
class JsonExporterPipline(object):
def __init__(self):
self.file = open('article.json', 'wb')
self.expore = JsonItemExporter(self.file, encoding='utf-8')
self.expore.start_exporting()
def close_spider(self):
self.expore.finish_exporting()
self.file.close()
def process_item(self, item, spider):
self.expore.export_item(item)
return item