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 8279373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:19:01+00:00 2026-06-08T09:19:01+00:00

To keep things organized I determined there are three item classes that a spider

  • 0

To keep things organized I determined there are three item classes that a spider will populate.

Each item class has a variety of fields that are populated.

class item_01(Item):
    item1 = Field()
    item2 = Field()
    item3 = Field()

class item_02(Item):
    item4 = Field()
    item5 = Field()

class item_03(Item):
    item6 = Field()
    item7 = Field()
    item8 = Field()

There are multiple pages to crawl with the same items.
In the spider I use XPathItemLoader to populate the ‘containers’.

The goal is to pass the items to a mysql pipeline to populate a single table. But here is the problem.

When I yield the three containers (per page) they are passed as such into the pipeline, as three separate containers.
They go through the pipeline as their own BaseItem and populate only their section of the mysql table, leaving the other columns ‘NULL’.

What I would like to do is repackage these three containers into a single BaseItem so that they are passed into the pipeline as a single ITEM.

Does anyone have any suggestions as to repackage the items? Either in the spider or pipeline?

Thanks

  • 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-06-08T09:19:03+00:00Added an answer on June 8, 2026 at 9:19 am

    I did this hack to get things moving but if someone can improve or hint at a better solution please share it.

    Loading my items in the spider like this:

    items = [item1.load_item(), item2.load_item(), item3.load_item()]  
    

    I then defined a function outside the spider:

    def rePackIt(items):
        rePackage = rePackageItems()
        rePack = {}
        for item in items:
            rePack.update(dict(item))
    
        for key, value in rePack.items():
            rePackage.fields[key] = value
        return rePackage  
    

    Where in the items.py I added:

    class rePackageItems(Item):
        """Repackage the items"""
        pass  
    

    After the spider is done crawling the page and loading items I yield:

    yield rePackIt(items)  
    

    which takes me to the pipelines.py.

    In the process_item to unpack the item I did the following:

    def process_item(self, item, spider):
            items = item.fields
    

    items is now a dictionary that contains all the extracted fields from the spider which I then used to insert into a single database table

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To keep things simple, lets say I have a Node class, each node has
To keep things simple, please allow the assumption that some code requires the use
Just to keep things interesting and close my final open question, the solution that
I want to add folders to keep things organized in App_LocalResources . Because when
To keep things simplified lets say I have an interface RandomProvider interface public interface
I'm a big fan of backing things up. I keep my important school essays
I try to keep things as local as possible, so I put enums at
If I just want to keep things very simple, and just map my tables
I'm using NHibernate to persist my domain objects. To keep things simple I'm using
I'm trying to build a new Orchard theme, and to keep things structures I'd

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.