fix handle items not found
This commit is contained in:
parent
0cfe551ce5
commit
73d4101325
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user