title: How to export data automatically to CSV with Scrapy Feed
body: <p>I am trying to automatically generate a CSV every time I execute Scrapy crawl (myspider). I have tried to use Scrapy feeds, but I am getting the following error:</p>
  <blockquote>
  <p>error.ReactorNotRestartable()
  twisted.internet.error.ReactorNotRestartable</p>
  </blockquote>
  <p>This is my code:</p>
  <pre><code>import scrapy
  import json
  from ..items import inmobiliarias
  from scrapy import Spider
  from scrapy.selector import Selector
  
  
  class IdealistaSpider(scrapy.Spider):
      name = 'idealista'
      custom_setting = {'FEEDS': {'/Users/aleja/Documentos OneDrive/items.csv':{'format': 'csv'}}}
  
      def start_requests(self):
          url = 'https://www.idealista.com/areas/venta-viviendas/pagina-{page}?shape=%28%28osyuFrkkUqPo%60%40rEaGxm%40UA%7ERRnInApEgUlBkG%7DCiGtE%29%29'
          headers = {
      &quot;authority&quot;: &quot;www.idealista.com&quot;,
      &quot;cache-control&quot;: &quot;max-age=0&quot;,
      &quot;sec-ch-ua&quot;: &quot;\&quot;Chromium\&quot;;v=\&quot;94\&quot;, \&quot;Google Chrome\&quot;;v=\&quot;94\&quot;, \&quot;;Not A Brand\&quot;;v=\&quot;99\&quot;&quot;,
      &quot;sec-ch-ua-mobile&quot;: &quot;?0&quot;,
      &quot;sec-ch-ua-platform&quot;: &quot;\&quot;Windows\&quot;&quot;,
      &quot;upgrade-insecure-requests&quot;: &quot;1&quot;,
      &quot;user-agent&quot;: &quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36&quot;,
      &quot;accept&quot;: &quot;text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9&quot;,
      &quot;sec-fetch-site&quot;: &quot;none&quot;,
      &quot;sec-fetch-mode&quot;: &quot;navigate&quot;,
      &quot;sec-fetch-user&quot;: &quot;?1&quot;,
      &quot;sec-fetch-dest&quot;: &quot;document&quot;,
      &quot;accept-language&quot;: &quot;es-ES,es;q=0.9&quot;
  }
          for page in range(1,5):
              yield scrapy.Request(url = url.format(page = page), headers = headers, callback = self.parse_json)
  
      def parse_json(self, response):
          #from scrapy.shell import inspect_response
          #inspect_response(response, self)
          sel = Selector(text= response.text)
          item = sel.xpath('//div[@class=&quot;item-info-container&quot;]').extract()
          items = inmobiliarias()
          for element in item:
              sel = Selector(text = element)
              items['title'] = sel.xpath('//a[@role=&quot;heading&quot;]/@title').extract()
              items['price'] = sel.xpath('//div/span[@class=&quot;item-price h2-simulated&quot;]/text()').extract()
              items['phone'] = sel.xpath('//span[@class=&quot;icon-phone item-not-clickable-phone&quot;]/text()').extract()
              items['url'] = 'https://www.idealista.com' + sel.xpath('//a[@role=&quot;heading&quot;]/@href')[0].extract()
              items['meters'] = sel.xpath('//span[small/text()=&quot;m²&quot;]/text()').extract()
              items['rooms'] = sel.xpath('//span[small/text()=&quot;hab.&quot;]/text()').extract()
              items['real_state'] = sel.xpath('//picture[@class=&quot;logo-branding&quot;]/a//@alt').extract()
              items['garage'] = sel.xpath('//div/span[@class=&quot;item-parking&quot;]/text()').extract()
              last_item_detail = sel.xpath('//span[@class=&quot;item-detail&quot;]/text()')[-1].extract()
              if last_item_detail != items['meters'] and last_item_detail != items['rooms']:
                  items['floor'] = last_item_detail
              else:
                  items['floor'] = ''
              yield items
  </code></pre>