Fixed exception handling

This commit is contained in:
Joan
2023-09-05 10:24:19 +02:00
parent a60aa4c580
commit b717e9fdc4

View File

@@ -45,15 +45,15 @@ def get_image(soup, etree_soup):
image = dom.xpath('//*[@id="main-image-container"]/ul/li[4]/span/span/div/img')
image = image[0].get('src')
except IndexError:
logging.info("Couldn't retrieve image, trying with xpath method")
dom = etree.HTML(str(etree_soup))
image = dom.xpath('//*[@id="main-image-container"]/ul/li[5]/span/span/div/img')
image = image[0].get('src')
except AttributeError:
logging.info("Couldn't retrieve image with xpath method, falling back to placeholder")
image = "N/A"
except Exception as e:
logging.info(f"Error retrieving image: {e}")
try:
logging.info("Couldn't retrieve image, trying with xpath method 2")
dom = etree.HTML(str(etree_soup))
image = dom.xpath('//*[@id="main-image-container"]/ul/li[5]/span/span/div/img')
image = image[0].get('src')
except Exception as e:
logging.info("Couldn't retrieve image with xpath method, falling back to placeholder")
logging.info(f"Error retrieving image: {e}")
image = "N/A"
except Exception as e:
logging.info(f"Error retrieving image: {e}")