2

I have Scrapy Item, for example:

class QuotetutorialItem(scrapy.Item):
    url = scrapy.Field()
    country = scrapy.Field() 
    state = scrapy.Field()

When I yield this Item, i get fields in alphabetical order.

How I can keep the fields order the same as in class structure?

Дядя Фея
  • 359
  • 2
  • 12

1 Answers1

2

You can make use of the following attribute custom_settings

class YourSpiderClass(scrapy.Spider):
    name = 'spider_name'
    start_urls = ['http://blahblah.com/']

    custom_settings = {
            'FEED_URI': 'file.csv',
            'FEED_FORMAT': 'csv',
            'FEED_EXPORT_FIELDS': [
                'Url',
                'Country',
                'State',
             ],
         }

    def parse(self, response):
    # you actions
GmrYael
  • 385
  • 3
  • 11