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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:08:30+00:00 2026-05-31T14:08:30+00:00

Recently started working with the scrapy library. I am trying to scrape from a

  • 0

Recently started working with the scrapy library. I am trying to scrape from a web site that has slightly different tables for each kind of product they sell. Eventually, I will use the data to populate object attributes. For now, I just need to extract it to JSON format.

Here is an example table:

<table id="table_1">
<tr id="row_1">
    <td>cell_1</td>
    <td>cell_2</td>
    <td>cell_3</td>
</tr>
<tr id="row_2">
    <td>cell_4</td>
    <td>cell_5</td>
    <td>cell_6</td>
</tr>
<tr id="row_n">
    <td>cell_x</td>
    <td>cell_y</td>
    <td>cell_z</td>
</tr>
</table>

Each column represents a different item, ie, small medium or large t-shirts.
There would be 3 items in the table above, so the Items would look like:

Item 1 {
    row_1:cell_1
    row_2:cell_4
    row_n:cell_x
}
Item 2 {
    row_1:cell_2
    row_2:cell_5
    row_n:cell_y
}
Item 3 {
    row_1:cell_3
    row_2:cell_6
    row_n:cell_z
}

They are well-structured tables with no ‘missing’ or ‘extra’ cells, although the number of rows and columns is arbitrary.

The difficulty I had was in using the scrapy Item object, as this requires my Item class to define the number of Fields before scraping, instead of on a per-table basis. I have hundreds of tables I want to perform this process on.

Thanks for reading this far, any help is appreciated. 🙂

RESOLUTION: @warawuk Thanks for your help. I used your suggestion, and ended up with a triple-nested list. Perhaps not ideal, but it is trivial enough to extract the values as I continue working with them:

{"tRows": 
    [[["row1"], ["cell1", "cell2"]]
    [["row2"], ["cell3", "cell4"]]
    [["row3"], ["cell5", "cell6"]]
    [["row4"], ["cell7", "cell8"]]] x100s of tables
}

To deal with the arbitrary number of rows, I used a regular expression to extract the ids from each row and count them. A simple loop using range(len(rowNames)), plus some string concatenation finished the job.

  • 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-31T14:08:31+00:00Added an answer on May 31, 2026 at 2:08 pm

    You have too many questions here, imo.

    First of all, looks like your question is not about scrapy at all. It’s about organizing your data and xpath.

    I think you must split your task in subtasks. First subtask is to actually extract the data into a python data structure and then try to process it. From your info, i think the data will like:

    {
        'table_1': {
            'row_1': ['cell_1', 'cell_2'],
            'row_2': ['cell_1', 'cell_2'],
            ...
        },
        'table_2': {
            'row_1': ['cell_1', 'cell_2', 'cell_3'],
            'row_2': ['cell_1', 'cell_2', 'cell_3'],
            ...
        },
    }
    

    Is this correct?


    UPDATE:

    The difficulty I had was in using the scrapy Item object, as this
    requires my Item class to define the number of Fields before scraping,
    instead of on a per-table basis. I have hundreds of tables I want to
    perform this process on.

    AFAIK, Item Fields can store any Python object. Scrapy Item class is just a place where you store Fields, but scrapy does not treat these fields in a special way. It’s just you who takes these Fields in a pipeline and interprets data in them.

    So choose any store format that suites you. For example:

    class Shirt(Item):
        available_sizes = Field() # [(size1, amount1), (size2, amount2), ...] or {size1: amount1, size2: amount2, ...} if `size` is a hashable object
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is OSCommerce outdated? I recently started working for a web development company that uses
I have recently started working on a legacy application that has most of its
I have recently started working on a very large C++ project that, after completing
I have recently started working on an app which has both Java and native
I have recently started working on my master thesis in C that I haven't
I recently started working in VS2010 and noticed right away that the font I
I have recently started working on a web application at a new company and
I've recently started working on a project that uses bazaar. I'm attempting to find
I've recently started working on a web app with a new company and found
I'm working on a REST client library, and recently started working on adding support

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.