比如設(shè)置了一個判斷條件:
if requests.get(so_url,proxies=proxy,headers=headers).status_code == 200:
html = requests.get(so_url,proxies=proxy,headers=headers).text
url = re.search('<div class="img-box">.*?<a.*?href="(.*?)"><span>',html,re.S).group(1).replace('amp;','')
print(url)
else:
proxy = str(proxy).replace("{'http': 'http://",'').replace("'}",'')
#當條件不滿足時,想要重試請求幾次
請問這種邏輯該怎么設(shè)計?一開始在else下直接調(diào)用了該函數(shù),可是后來好像有內(nèi)存溢出的情況?后來干脆把上面的判斷在else下又寫了一遍,可是也只能重試一次...
想要的效果是,如果走到else了,那就把判斷條件再重試N次...
if的條件沒滿足,想要重試幾次,這種邏輯怎么操作?
慕碼人8056858
2019-02-18 02:46:36