Scrapy框架: pipelines.py设置
2024-09-04 04:21:10
保存数据到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()
最新文章
- 18.实现如下类之间的继承关系,并编写Music类来测试这些类。
- strlen和sizeof的区别
- 【Python】[函数] 函数的参数与递归函数
- display:inline-block 在IE6中实现{转}
- WinForms 新窗体后台打开完美的解决
- Codeforces #345 Div.1
- 域名系统DNS和FTP
- Python初探
- 对于ArrayList中的泛型进行分析
- <;HTML>;初识HTML
- python re模块记录
- Roller5.0.3安装配置部署 step by step
- Python爬虫——小说
- hexo上部署博客到Github失败
- 20145234黄斐《Java程序设计》课程总结
- IntelliJ IDEA 自动编译功能无法使用,On &#39;update&#39; action:选项里面没有update classes and resources这项
- c++计算器后续(3)
- static变量和final变量
- Markdown 学习
- Android NDK r8 Cygwin CDT 在window下开发环境搭建 安装配置与使用 具体图文解说