I am new to programming and I am trying to handle errors on my web scraping program. I iterate from a product list through 3 websites (A, B and C) looking for the product's name and product's price. For example i want this output:
print(productA, priceA, productB, priceB, productC, price C)
But sometimes some products do not store let say the price or the products name because it maybe be out of stock or it just can't find it and brings an AttributeError.
Because of this, I add a long list of exceptions on my program to print "not available" in each case it can't find the item's name or price it is looking for.
try:
print(productA, priceA, productB, priceB, productC, price C)
except AttributeError:
try:
print("not available", priceA, productB, priceB, productC, price C)
except AttributeError:
try:
print(productA, "not available", productB, priceB, productC, price C)
except AttributeError:
try:
print("not available", "not available", productB, priceB, productC, price C)
...
And so on for the three products, trying to see if one, two, or the three items' name or price may be missing and bringing up the error. My question is, is there a way to make this easier/faster or automate it so the code won't be so long? Thanks