当前位置: 代码迷 >> 综合 >> scrapy----将数据保存到excel中
  详细解决方案

scrapy----将数据保存到excel中

热度:54   发布时间:2023-12-24 20:54:46.0

1.在pipelines.py中自定义自己的pipeline

from openpyxl import Workbook
class ExcelPipeline(object):def __init__(self):self.wb = Workbook()self.ws = self.wb.activeself.ws.append(['工作名称', '工作地点', '薪资', '公司名称', '工作经验', '学历', '招收人数', '发布时间', '工作信息'])def process_item(self, item, spider):line = [item['job_name'], item['job_place'], item['salary'], item['company'], item['experience'], item['education_level'], item['person_num'], item['release_time'], item['info']]self.ws.append(line)self.wb.save('job.xlsx')return item

2.在settings.py中开启自己的pipeline

ITEM_PIPELINES = {'Job.pipelines.ExcelPipeline': 1,
}

  相关解决方案