Fixed exception handling
This commit is contained in:
@@ -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 = dom.xpath('//*[@id="main-image-container"]/ul/li[4]/span/span/div/img')
|
||||||
image = image[0].get('src')
|
image = image[0].get('src')
|
||||||
except IndexError:
|
except IndexError:
|
||||||
logging.info("Couldn't retrieve image, trying with xpath method")
|
try:
|
||||||
dom = etree.HTML(str(etree_soup))
|
logging.info("Couldn't retrieve image, trying with xpath method 2")
|
||||||
image = dom.xpath('//*[@id="main-image-container"]/ul/li[5]/span/span/div/img')
|
dom = etree.HTML(str(etree_soup))
|
||||||
image = image[0].get('src')
|
image = dom.xpath('//*[@id="main-image-container"]/ul/li[5]/span/span/div/img')
|
||||||
except AttributeError:
|
image = image[0].get('src')
|
||||||
logging.info("Couldn't retrieve image with xpath method, falling back to placeholder")
|
except Exception as e:
|
||||||
image = "N/A"
|
logging.info("Couldn't retrieve image with xpath method, falling back to placeholder")
|
||||||
except Exception as e:
|
logging.info(f"Error retrieving image: {e}")
|
||||||
logging.info(f"Error retrieving image: {e}")
|
image = "N/A"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.info(f"Error retrieving image: {e}")
|
logging.info(f"Error retrieving image: {e}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user