scrapy----將資料儲存到excel中
阿新 • • 發佈:2019-01-11
1.在pipelines.py中自定義自己的pipeline
from openpyxl import Workbook class ExcelPipeline(object): def __init__(self): self.wb = Workbook() self.ws = self.wb.active self.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,
}