Move logic in case the captcha resolution fails or we can't extract the data after the captcha resolution to avoid errors
This commit is contained in:
10
bot/bot.py
10
bot/bot.py
@@ -119,13 +119,13 @@ def find_amazon_link(update: Update, context: CallbackContext) -> None:
|
|||||||
logging.info("Re-loading Amazon webpage")
|
logging.info("Re-loading Amazon webpage")
|
||||||
page_html = load_page(url=amazon_url_with_referer, driver=chrome_driver, screenshot_type="_aftercaptcha")
|
page_html = load_page(url=amazon_url_with_referer, driver=chrome_driver, screenshot_type="_aftercaptcha")
|
||||||
product_data = scrape_data(page_html)
|
product_data = scrape_data(page_html)
|
||||||
|
|
||||||
if not product_data:
|
|
||||||
logging.info("Unable to get the product information")
|
|
||||||
context.bot.send_message(chat_id=chat_id, text="Unable to get product attributes from the provided url", reply_to_message_id=message_id)
|
|
||||||
return
|
|
||||||
else:
|
else:
|
||||||
logging.info("Couldn't solve the captcha, if there was any")
|
logging.info("Couldn't solve the captcha, if there was any")
|
||||||
|
|
||||||
|
if not product_data: #if after applying the captcha we don't have any data yet, stop the execution and reply to the user
|
||||||
|
logging.info("Unable to get the product information")
|
||||||
|
context.bot.send_message(chat_id=chat_id, text="Unable to get product attributes from the provided url", reply_to_message_id=message_id)
|
||||||
|
return
|
||||||
|
|
||||||
logging.info(f"Product information found: {product_data}")
|
logging.info(f"Product information found: {product_data}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user