class ItcastPipeline(object):
def init(self):
self.f = open(“itcast_pipelines.json”,“w”)
def process_item(self, item, spider):
content = json.dumps(dict(item), ensure_ascii=False) + ", \n"
self.f.write(content.encode("utf-8"))
return item
#返回给引擎
def close_spider(self,spider):
self.f.close()
将文件打开方式改为wb二进制方式打开,解决问题