fix handle items not found

This commit is contained in:
Sam Hadow 2024-07-21 00:29:00 +02:00
parent 0cfe551ce5
commit 73d4101325

View File

@ -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. 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)') 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]+') number_regex = re.compile(r'[0-9]+')
price_regex = re.compile(r'[0-9]*,[0-9]{0,2}') 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 # check if punish page hit
punish = bool(re.search(punish_regex, driver.page_source)) 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: if punish:
print("punish page") print("punish page")
driver.quit() driver.quit()
raise ValueError("punish") raise ValueError("punish")
elif not_found:
print("item not found")
return {}
else: else:
# refresh page to have the price in a single span # refresh page to have the price in a single span
driver.refresh() driver.refresh()
@ -171,6 +164,8 @@ def check_item(settings_item):
print(f"The extracted price is: {price}, the extracted currency is: {currency}") print(f"The extracted price is: {price}, the extracted currency is: {currency}")
except Exception as e: except Exception as e:
print(f"An error occurred: {e}") print(f"An error occurred: {e}")
print("item not found")
return {}
# discount percentage # discount percentage
discount = 0 discount = 0