Reputation: 3068
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
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