21、 Python快速开发分布式搜索引擎Scrapy精讲—爬虫数据保存
注意:数据保存的操作都是在pipelines.py文件里操作的 将数据保存为json文件 spider是一个信号检测 #-*-coding:utf-8-*- #Defineyouritempipelineshere # #Don'tforgettoaddyourpipelinetotheITEM_PIPELINESsetting #See:http://doc.scrapy.org/en/latest/topics/item-pipeline.html fromscrapy.pipelines.imagesimportImagesPipeline#导入图片下载器模块 importcodecs importjson classAdcPipeline(object):#定义数据处理类,必须继承object def__init__(self): self.file=codecs.open('shuju.json','w',encoding='utf-8')#初始化时打开json文件 defprocess_item(self,item,spider):#process_item(item)为数...