2018-10-24
閱讀量:
1388
python爬蟲中斷問題和處理1
報錯:requests.exceptions.ConnectionError
原因:
網(wǎng)絡(luò)問題出現(xiàn)的異常事件(如DNS錯誤,拒絕連接,等等),這是Requests庫中自帶的異常
解決方法:
1.捕捉基類異常,一次解決
try:
r = requests.get(url, params={’s’: thing})
except requests.exceptions.RequestException as e: # This is the correct syntax
print e
sys.exit(1)
2.分別處理各種異常,比如:
r = requests.get(url, params={’s’: thing})
except requests.exceptions.Timeout:
except requests.exceptions.TooManyRedirects:
except requests.exceptions.RequestException as e:
print e
sys.exit(1)






評論(0)


暫無數(shù)據(jù)
推薦帖子
0條評論
0條評論
0條評論