看板 Python 關於我們 聯絡資訊
def get_webpage(url): try: resp = requests.get( url=url ) if resp.status_code != 200: print('無法取得此網頁 網址為: [' + resp.url + ']') return None else: return resp.text except Exception as e: print('開啟網頁錯誤! 網頁url: [' + url + '], 錯誤訊息: ' + str(e)) for i in range(10): print('等待10分鐘: ' + str(i))) sleep(60) try: resp = requests.get( url=url ) if resp.status_code != 200: print('*無法取得此網頁 網址為: [' + resp.url + ']*') return None # 看要不要改別的 else: return resp.text except Exception as e: print('*!* 連續開啟網頁二次錯誤! 網頁url:' + url) sys.exit() ※ 引述《loser113 (洨大魯蛇ㄍ)》之銘言: : 現在遇到爬蟲網站會看ip 抓太多會斷你連結 : 那我迴圈中間遇到錯誤 怎麼寫暫停一下 : 之後從這輪錯誤的迴圈再開始跑 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.192.184.90 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1574933562.A.1B1.html