From 73d4101325a37accd2944dd84eb82a44db4938f7 Mon Sep 17 00:00:00 2001 From: Sam Hadow Date: Sun, 21 Jul 2024 00:29:00 +0200 Subject: [PATCH] fix handle items not found --- src/aliexpress.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/aliexpress.py b/src/aliexpress.py index 2a83b18..08f48ad 100644 --- a/src/aliexpress.py +++ b/src/aliexpress.py @@ -42,7 +42,6 @@ def check_item(settings_item): itemid is in aliexpress link to item page. attributes is a list of string. Each string is a choice value (for example which length, or which colour) if multiple items are on the same page, only one by category, order doesn't matter. ''' punish_regex = re.compile(r'(pid: \'punish-page\')|(Deny from x5)|(FAIL_SYS_ILLEGAL_ACCESS)') - not_found_regex = re.compile(r'(Sorry, the page you requested can not be found)|(https://ae01.alicdn.com/kf/S01523ef93482448d8c33d410344d6a9eI/361x360.png)') number_regex = re.compile(r'[0-9]+') price_regex = re.compile(r'[0-9]*,[0-9]{0,2}') @@ -100,17 +99,11 @@ def check_item(settings_item): # check if punish page hit punish = bool(re.search(punish_regex, driver.page_source)) - # check if the item exists - not_found = bool(re.search(punish_regex, driver.page_source)) - if punish: print("punish page") driver.quit() raise ValueError("punish") - elif not_found: - print("item not found") - return {} else: # refresh page to have the price in a single span driver.refresh() @@ -171,6 +164,8 @@ def check_item(settings_item): print(f"The extracted price is: {price}, the extracted currency is: {currency}") except Exception as e: print(f"An error occurred: {e}") + print("item not found") + return {} # discount percentage discount = 0