我有一個檢查 URL 的功能input,但是,只有兩個選項,即 Amazon 和 Aliexpress,所以我試圖檢查輸入的鏈接是否input屬于兩個站點之一,但我不是在做了
def url_check(values):
amazon_url = 'https://www.amazon.com'
aliexpress_url = 'https://best.aliexpress.com/'
if amazon_url not in values['url_input']:
sg.popup_error('URL Error','The URL does not belong to the specified site!')
raise ValueError('The URL does not belong to the specified site!')
if not aliexpress_url in values['url_input']:
sg.popup_error('URL Error','The URL does not belong to the specified site!')
raise ValueError('The URL does not belong to the specified site!')
注意:我不能使用==,in因為輸入將指定從其中一個站點到產品的鏈接,而不是站點的主頁 url。
uj5u.com熱心網友回復:
我不完全理解你在問什么或有什么問題,但如果提供的網站不屬于亞馬遜,你總是會拋出錯誤。您應該遍歷所有要檢查的站點,并僅在沒有匹配項時引發例外
def url_check(values):
valid_urls = ['https://www.amazon.com', 'https://best.aliexpress.com/']
for url in valid_urls:
if url in values['url_input']:
return # or do whatever
sg.popup_error('URL Error','The URL does not belong to the specified site!')
raise ValueError('The URL does not belong to the specified site!')
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/465615.html
標籤:Python
