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()
except: passyou'll never know why your code fails.