pipelines.py文件中

 

import codecs
import csv

# 保存到CSV文件中
class CsvPipeline(object):

    def __init__(self):
        self.file = codecs.open('a.csv', 'w', encoding='utf_8_sig')

    def process_item(self, item, spider):
        fieldnames = ['title', 'img_url', 'download_http']
        w = csv.DictWriter(self.file, fieldnames=fieldnames)
        w.writerow(item)
        return item

    def close_spider(self, spider):
        self.file.close()

 

相关文章:

  • 2021-07-21
  • 2021-10-23
  • 2021-12-19
  • 2021-11-09
  • 2022-01-08
  • 2021-08-02
  • 2022-12-23
  • 2021-12-20
猜你喜欢
  • 2022-01-17
  • 2021-08-16
  • 2022-12-23
  • 2021-08-13
  • 2021-11-28
  • 2022-12-23
相关资源
相似解决方案