title: writing data into multiple sheets in a single csv file from python/scrapy(python framework)
body: <p>I am using scrapy framework and fetched data from two urls by creating two spider files.</p>
  
  <p>Now for example when i run the <code>spider1</code> for <code>url1</code> the data scraped will be saved in to <code>csv1</code> file, when i run the second <code>spider2</code> the data will be saved in to <code>csv2</code> file.</p>
  
  <p>Actually what i am trying to do is saving all the data from different spiders in to a single csv file in different sheets(sheet name should be as spider name) </p>
  
  <pre><code>All about my question is how to write data in to multiple sheets in a single csv file from python
  </code></pre>
  
  <p><strong>pipeline.py</strong></p>
  
  <pre><code>from w3c_browser.items import WCBrowserItem
  import csv
  from csv import DictWriter
  from cStringIO import StringIO
  from datetime import datetime
  from scrapy.xlib.pydispatch import dispatcher
  from scrapy import signals
  from scrapy import log
  
  class W3CBrowserPipeline(object):
      def __init__(self):
          dispatcher.connect(self.spider_opened, signal=signals.spider_opened)
          dispatcher.connect(self.spider_closed, signal=signals.spider_closed)
          self.brandCategoryCsv = csv.writer(open('wcbbrowser.csv', 'wb'))
  
      def spider_opened(self, spider):
          spider.started_on = datetime.now()
          if spider.name == 'browser_statistics':
              log.msg("opened spider  %s at time %s" % (spider.name,datetime.now().strftime('%H-%M-%S')))
              self.brandCategoryCsv = csv.writer(open("csv/%s-%s.csv"% (spider.name,datetime.now().strftime('%d%m%y')), "wb"),
                         delimiter=',', quoting=csv.QUOTE_MINIMAL)
          elif spider.name == 'browser_os':
              log.msg("opened spider  %s at time %s" % (spider.name,datetime.now().strftime('%H-%M-%S')))
              self.brandCategoryCsv = csv.writer(open("csv/%s-%s.csv"% (spider.name,datetime.now().strftime('%d%m%y')), "wb"),
                         delimiter=',', quoting=csv.QUOTE_MINIMAL)
          elif spider.name == 'browser_display':
              log.msg("opened spider  %s at time %s" % (spider.name,datetime.now().strftime('%H-%M-%S')))
              self.brandCategoryCsv = csv.writer(open("csv/%s-%s.csv"% (spider.name,datetime.now().strftime('%d%m%y')), "wb"),
                         delimiter=',', quoting=csv.QUOTE_MINIMAL)
  
      def process_item(self, item, spider):
          if spider.name == 'browser_statistics':
              self.brandCategoryCsv.writerow([item['year'],
                                              item['internet_explorer'],
                                              item['firefox'],
                                              item['chrome'],
                                              item['safari'],
                                              item['opera'],
              ])
              return item
  
          elif spider.name == 'browser_os':
              def process_item(self, item, spider):
                  self.brandCategoryCsv.writerow([item['year'],
                                                  item['vista'],
                                                  item['nt'],
                                                  item['winxp'],
                                                  item['linux'],
                                                  item['mac'],
                                                  item['mobile'],
                  ])
                  return item
  
      def spider_closed(self, spider):
          log.msg("closed spider %s at %s" % (spider.name,datetime.now().strftime('%H-%M-%S')))
          work_time = datetime.now() - spider.started_on
          print str(work_time),"Total Time taken by the spider to run&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;"
  </code></pre>