scrapy持久化到Excel表格
前提条件: 防止乱码产生 ITEM_PIPELINES = { 'xpc.pipelines.ExcelPipeline': 300, } 方法一 1、安装openpyxl conda install openpyxl 2、pipline from openpyxl import Workbook class ExcelPipeline(object): def __init__(self): # 创建excel, 填写表头 self.wb = Workbook() self.ws = self.wb.active # 设置表头 self.ws.append(['ID', '标题', 'URL']) def process_item(self, item, spider): # 把数据的每一项整理出来 line = [item['pid'], item['title'], item['src']] # 将数据以行的形式添加到xlsx中 self.ws.append(line) # 保存xlsx文件中 self.wb.save('work.xlsx') return item 3、setting ITEM_PIPELINES = { 'xpc.pipelines.ExcelPipeline': 300, } 方法二 scrapy crawl work -o work.csv