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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:26:35+00:00 2026-06-10T11:26:35+00:00

I’m using Scrapy and xpaths to grab a bunch of sold property data from

  • 0

I’m using Scrapy and xpaths to grab a bunch of sold property data from a website. There are 9 different ‘items’ in total (sale price, date sold, agent, agency, address, type of property, bedrooms, bathrooms, and full URL) and 20 records per page. I then deposit the results into an SQLite3 database.

Everything works perfectly well until I hit a page with slightly incomplete data. If a variable is missing from even a single record, it screws everything up and nothing from the page gets written to the database.

I’m pretty sure this is because I have coded things in an ‘unpythonic’ way but can’t figure out a solution (pythonic or otherwise) to this problem.

This is the part of my pipelines.py file where things seem to be going wrong:

def process_item(self, item, spider):

    self.cur.execute("CREATE TABLE IF NOT EXISTS Diditwork(Id INTEGER PRIMARY KEY, SalePrice TEXT, Address TEXT, Agent TEXT, Agency TEXT, DateSold TEXT, TypeOfProperty TEXT, Bedrooms TEXT, Bathrooms TEXT, FullURL TEXT)")
    n=int(0)
    for data in item['address']:

        self.cur.execute("INSERT INTO Diditwork (Saleprice, Agent, Agency, Address, DateSold, TypeOfProperty, Bedrooms, Bathrooms, FullURL) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", ((item['saleprice'][n]), (item['agent'][n]), (item['agency'][n]), (item['address'][n]), (item['datesold'][n]), (item['typeofproperty'][n]), (item['bedrooms'][n]), (item['bathrooms'][n]), (item['fullurl'][n])))

        self.conn.commit()
        n +=1

    return item

The error I get when a variable is missing from a record is ‘exceptions.IndexError: list index out of range’

I think this is because of the way my loop is written. It will look for lists with 20 variables in them, but on some pages if one or more records are incomplete or missing it tries to call a list index that doesn’t exist.

For example, on one page there may be 20 adress records but only 15 agent records. It tries to call item[‘agent’][16] and then spits back an error because the list isn’t that long.

Anyway, my apologies for the poor explanation of my problem. I’m not sure if I should be trying to implement some kind of error handling like

if len(item['address']) != len(item['agent']): 
            #item['agent'] = ["not available"] * 20 

Or whether my whole approach is wrong.

Any assistance would be most appreciated – I’m a bit out of my depth here and have been trying for the better part of a day and a half to resolve this problem on my own.

EDIT: Thanks guys. I still have more testing to do, but I think I actually ended up figuring this one out. Here’s the code I’m using. I’ll leave this one as unanswered for 24 hours in case someone comes up with a more elegant solution.

if len(item['address']) != len(item['agent']): #error checking
            difference = len(item['address']) - len(item['agent']) #find the disparity
            item['agent'].extend(["not available"] * difference) #append/extend the list by an appropriate number 
  • 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-10T11:26:36+00:00Added an answer on June 10, 2026 at 11:26 am

    Your approach is compact, requires less code and less processing so it is fine. All you are lacking is proper validation. Any data entered to the db must be validated , its not only the length but also field types that you should validate and fix before parsing and storing.

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

Sidebar

Related Questions

I have a bunch of posts stored in text files formatted in yaml/textile (from
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am currently running into a problem where an element is coming back from
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build

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.