0

I was trying to scrape with python and write to database, i parsed 50 items but when i checked to database shows 16 items. Does anybody knows why and how can i fix that. Thank you. Here is my code below:

while page < 100:
    try:
        url = ""
        urllib.request.urlopen(url).read()
        response = urllib.request.urlopen(url).read()
        json_obj = json.loads(response.decode('ISO-8859-1'))
        print(json_obj)
        time.sleep(5)
        for product in json_obj["items"]:
            cursor.execute(
                "INSERT INTO inventory (upc) VALUES (%s)", (product["upc"]))


    except:
        pass
    con.commit()
    page = page + 25
    print(page)
con.close()
2
  • 5
    If you're ignoring all errors with except: pass you'll never know why your code fails. Commented Jul 28, 2020 at 23:32
  • Take a look at this post! This might help you how to handle error thrown by your database connection. stackoverflow.com/questions/30996401/… Commented Jul 28, 2020 at 23:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.