CsvItemExporter has an option join_multivalued
that defaults to a comma (=','
).
How can i change this to another char in my scrapy project?
CsvItemExporter has an option join_multivalued
that defaults to a comma (=','
).
How can i change this to another char in my scrapy project?
Set it in your custom CSVItemExporter
this way:
from scrapy.conf import settings
from scrapy.contrib.exporter import CsvItemExporter
class CSVkwItemExporter(CsvItemExporter):
def __init__(self, *args, **kwargs):
kwargs['fields_to_export'] = settings.getlist('EXPORT_FIELDS') or None
kwargs['encoding'] = settings.get('EXPORT_ENCODING', 'utf-8')
super(CSVkwItemExporter, self).__init__(*args, **kwargs)
self._join_multivalued = settings.get('MY_CSV_DELIMITER', ',')
where MY_CSV_DELIMITER
is an example setting you would have for a delimiter.
from scrapy.conf import settings
from scrapy.exporters import CsvItemExporter
class MyCsvItemExporter(CsvItemExporter):
def __init__(self, *args, **kwargs):
delimiter = settings.get('CSV_DELIMITER', ';')
kwargs['delimiter'] = delimiter
super(MyCsvItemExporter, self).__init__(*args, **kwargs)
FEED_EXPORT_ENCODING = 'utf-8'
FEED_EXPORTERS = {
'csv': 'your_scrapy_project.exporters.MyCsvItemExporter',
}
CSV_DELIMITER = ';'