前提条件:

防止乱码产生

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

用Excel文件打开csv,我的会出现乱码,暂时未解决

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-11
  • 2021-09-11
  • 2021-07-02
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-06
  • 2022-12-23
  • 2022-02-16
  • 2021-07-15
  • 2022-12-23
相关资源
相似解决方案