import json
from itemadapter import ItemAdapter
class LianjiaPipeline:
def open_spider(self, spider):
self.file = open('lianjia.json', 'a', encoding='utf-8')
def close_spider(self, spider):
self.file.close()
def process_item(self, item, spider):
line = json.dumps(ItemAdapter(item).asdict(), ensure_ascii=False) + "n"
self.file.write(line)
return item
在pipeline文件加入如上代码
最后
以上就是单纯羽毛最近收集整理的关于scrapy将数据载入json文件的全部内容,更多相关scrapy将数据载入json文件内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复