Mar-28-2020, 05:04 AM
I don't know anything about working with requests and BeautifulSoup, but, I would say to put the statements in a try except statement like this.
try: title = soup.find(id = "productTitle" ).get_text() except: print("Title not found") try: price = soup.find(id = "priceblock_ourprice" ).get_text() except: print("Title not found")If you are having to iterate that over and over then I would suggest making it a function
def FindById(ID): try: return soup.find(id = ID).get_text() except: print("Error: could not find") title = FindById("productTitle") price = FindById("priceblock_ourprice")Hopefully this helps