handle items not found

This commit is contained in:
Sam Hadow 2024-07-21 00:12:18 +02:00
parent afdaa49f19
commit 0cfe551ce5

View File

@ -42,6 +42,7 @@ 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}')
@ -99,10 +100,17 @@ 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()