for category in settings.CATEGORIES:
    file = open('output/%s.xml' % category, 'w+b')
exporter = XmlItemExporter(file)
exporter.start_exporting()
self.exporters[category] = exporter

def spider_closed(self, spider):
    for exporter in self.exporters.values():
        exporter.finish_exporting()

def process_item(self, item, spider):
    self.exporters[item['category']].export_item(item)
return item
Separate output file for every url given in start_urls list of spider in scrapy