diff --git a/bot/parser.py b/bot/parser.py index f836687..2cf7a6c 100644 --- a/bot/parser.py +++ b/bot/parser.py @@ -45,16 +45,16 @@ 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}") - return image \ No newline at end of file + return image