Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSV Exports - Ordering of columns using scrapy crawl -o output.csv

Is there a way to specify the order of the columns in a CSV output using the -o parameter?

It seems to follow a random order and does not follow the order in the items.py file or when the item fields get populated in the scrape.

Thanks!

like image 431
Eric Valente Avatar asked Feb 06 '15 15:02

Eric Valente


2 Answers

There is a relevant field_to_export attribute in CsvItemExporter, but, as far as I understand, there is no way to set it from the command-line. You need to do it through the pipeline, see:

  • How can I use the fields_to_export attribute in BaseItemExporter to order my Scrapy CSV data?
like image 164
alecxe Avatar answered Sep 25 '22 06:09

alecxe


You can solve it from adding a line in settings.py

FEED_EXPORT_FIELDS = ['field1', 'field2', 'field3']
like image 34
Md. Sazol Avatar answered Sep 22 '22 06:09

Md. Sazol