Abhishek
Abhishek

Reputation: 3068

Tab Delimited csv instead of comma delimited in scrapy

I am currently using the command

scrapy crawl myspider -o output.csv -t csv

to get output csv files. These files by default are comma delimited. How do i get a tab delimited file instead?

Upvotes: 3

Views: 1930

Answers (1)

0x01h
0x01h

Reputation: 925

Use this solution to override Scrapy's default CSV writer delimiter.

scraper/exporters.py

from scrapy.exporters import CsvItemExporter


class CsvCustomSeperator(CsvItemExporter):
    def __init__(self, *args, **kwargs):
        kwargs['encoding'] = 'utf-8'
        kwargs['delimiter'] = '\t'
        super(CsvCustomSeperator, self).__init__(*args, **kwargs)

scraper/settings.py

FEED_EXPORTERS = {
    'csv': 'scraper.exporters.CsvCustomSeperator'
}

In terminal

$ scrapy crawl spider -o file.csv

Upvotes: 2

Related Questions