Export csv file from scrapy (not via command line)

前端 未结 3 1977
春和景丽
春和景丽 2020-12-14 08:56

I successfully tried to export my items into a csv file from the command line like:

   scrapy crawl spiderName -o filename.csv

My question

3条回答
  •  -上瘾入骨i
    2020-12-14 09:02

    Up-to-date answer is:

    Use build-in exporter. You can set filename as key. Config may look like:

    filename = 'export' 
    class mySpider(scrapy.Spider):
      custom_settings = {
        'FEEDS': {
          f'{filename}.csv': {
            'format': 'csv',
            'overwrite': True
          }
        }
      }
    

    Documentation: https://docs.scrapy.org/en/latest/topics/feed-exports.html#std-setting-FEEDS

提交回复
热议问题