import json
class SuningPipeline(object):
def open_spider(self, spider):
if spider.name == 'book':
self.f = open('book.jsonlines', 'w', encoding='utf8')
def process_item(self, item, spider):
if spider.name == 'book':
json.dump(item, self.f, ensure_ascii=False)
self.f.write('\n')
return item
def close_spider(self, spider):
if spider.name == 'book':
self.f.close()