Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7412089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:29:14+00:00 2026-05-29T06:29:14+00:00

Can someone check whether the code below is correct? The code is found at

  • 0

Can someone check whether the code below is correct?
The code is found at
http://readthedocs.org/docs/scrapy/en/0.14/topics/exporters.html

I believe it is incorrect because:

  • The class keeps track of multiple simultaneously open files for multiple spiders, however:
  • The exporter (which depends on the file) is overwritten each time a new spider is opened.

Thanks for any assistance.

class XmlExportPipeline(object):

    def __init__(self):
        dispatcher.connect(self.spider_opened, signals.spider_opened)
        dispatcher.connect(self.spider_closed, signals.spider_closed)
        self.files = {}

    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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:29:14+00:00Added an answer on May 29, 2026 at 6:29 am

    I think this question should be asked in scrapy-users group.

    AFAIK, since v0.14 Scrapy doesn’t suppport multiple spiders in one process (related discussion), so this code will work fine. And obvious fix for multiple spiders is to make exporters dict with spider keys:

    class XmlExportPipeline(object):
    
        def __init__(self):
            dispatcher.connect(self.spider_opened, signals.spider_opened)
            dispatcher.connect(self.spider_closed, signals.spider_closed)
            self.files = {}
            self.exporters = {}
    
        def spider_opened(self, spider):
            file = open('%s_products.xml' % spider.name, 'w+b')
            self.files[spider] = file
            self.exporters[spider] = XmlItemExporter(file)
            self.exporters[spider].start_exporting()
    
        def spider_closed(self, spider):
            self.exporters[spider].finish_exporting()
            file = self.files.pop(spider)
            file.close()
    
        def process_item(self, item, spider):
            self.exporters[spider].export_item(item)
            return item
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone tell me why the code below doesn't work. I think my theory
I wonder whether someone could help me please, From a tutorial I found online
How can I check whether a string represents a long, a double, or just
If you take a look at the code below you can see that I
Can someone tell me why this unit test that checks for exceptions fails? Obviously
Can someone explain it succinctly? Can it be used with non-Silverlight clients?
Can someone recommend an up to date library for data Sanitization in PHP ?
Can someone point me to an article that shows the dropdownlist being populated from
Can someone tell me why this processes all the files and then does it
Can someone share their experiences with s#arp architecture. we have decided to follow mvp

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.