scrapy生成csv工具(python3)
背景:自己写的简单爬取电影种子的爬虫,数据存储到csv文件
版本:python3
IDE:pycharm
环境:windows10
项目:scrapy爬虫
注:如使用,请自行修改,谢谢
# -*- coding: utf-8 -*- from scrapy.exporters import CsvItemExporter class CsvPrintPipeline(object): def open_spider(self, spider): print("开始输出CSV文件") self.file = open("C:/torrent.csv", "wb") self.exporter = CsvItemExporter(self.file, fields_to_export=["m_title", "m_type", "m_update_status", "m_update_time"]) 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() print("结束输出CSV文件")