No output in XML file using XMLITEMEXPORTER
Question: I am beginner to python and I am working with scrapy. I have used
xmlitemexporter to export my scraped data to xml file. But i get only
"<"/item"">" in the xml file. My items.py is like follow:

    
    
    from scrapy.item import Item, Field
    
    class WorkwithitemsItem(Item):
        title = Field()
        link = Field()
        publish = Field()
        description = Field()
    

And the spider is like:

    
    
    from scrapy import log
    from scrapy.spider import BaseSpider
    from scrapy.selector import Selector
    from workwithitems.items import WorkwithitemsItem
    
    
    class MySpider(BaseSpider):
        name = 'spidey'
        allowed_domains = ['ekantipur.com']
        start_urls = [
        'http://www.ekantipur.com/en/rss',
                      ]
        def parse(self, response):
            self.log('A response from %s just arrived!' % response.url)
            sel = Selector(response)
            title = sel.xpath('//title/text()').extract()
            link = sel.xpath('//link/text()').extract()
            publish = sel.xpath('//pubDate/text()').extract()
            description = sel.xpath('//description/text()').extract()
            WorkwithitemsItem(title = title[2:], link = link[2:], 
                  publish = publish, description = description[1:])
    

And the pipelines.py is:

    
    
    from scrapy import signals
    from scrapy.contrib.exporter import XmlItemExporter
    
    
    class XmlExportPipeline(object):
        def __init__(self):
            self.files = {}
    
        @classmethod
        def from_crawler(cls, crawler):
            pipeline = cls()
            crawler.signals.connect(pipeline.spider_opened, signals.spider_opened)
            crawler.signals.connect(pipeline.spider_closed, signals.spider_closed)
            return pipeline
    
        def spider_opened(self, spider):
            file = open('%s_products.xml' % spider.name, 'w+b')
            self.files[spider] = file
            self.exporter = XmlItemExporter(file)
            self.exporter.start_exporting()
    
        def spider_closed(self, spider):
            self.exporter.finish_exporting()
            file = self.files.pop(spider)
            file.close()
    
        def process_item(self, item, spider):
            self.exporter.export_item(item)
            return item
    

The settings.py is:

    
    
    BOT_NAME = 'workwithitems'
    SPIDER_MODULES = ['workwithitems.spiders']
    NEWSPIDER_MODULE = 'workwithitems.spiders'
    FEED_EXPORTERS_BASE = {
        'xml': 'scrapy.contrib.exporter.XmlItemExporter',
    }
    ITEM_PIPELINES = {
        'workwithitems.pipelines.XmlExportPipeline': 800,
    }
    

I can't figure out where my problem is.


Answer: Ok! I found the problem. What i did is just put a 'return' at the last line in
spider.py

    
    
    return WorkwithitemsItem(title = title[2:], link = link[2:], 
                                    publish = publish, description = description[1:]
                                    )
    

