zoukankan      html  css  js  c++  java
  • Scrapy框架: pipelines.py设置

    保存数据到json文件

    # -*- coding: utf-8 -*-
    
    # Define your item pipelines here
    #
    # Don't forget to add your pipeline to the ITEM_PIPELINES setting
    # See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
    
    from scrapy.exporters import JsonItemExporter
    
    class ErshouPipeline(object):
        def open_spider(self, spider):
            self.file=open('01ershou.json','wb')
            self.exporter=JsonItemExporter(self.file)
            self.exporter.start_exporting()
    
        def process_item(self, item, spider):
            self.exporter.export_item(item)
            return item
    
        def close_spider(self, spider):
            self.exporter.finish_exporting()
            self.file.close()
    
  • 相关阅读:
    Alpha版(内部测试版)发布
    冲刺2-3
    冲刺2-2
    冲刺2-1
    团队绩效评价
    改进方案
    意见汇总
    27组评价
    冲刺10
    SOA
  • 原文地址:https://www.cnblogs.com/hankleo/p/11829736.html
Copyright © 2011-2022 走看看