看板 Python 關於我們 聯絡資訊
爬蟲新手請教,程式碼結構如下: import requests url = 'http://www.abc.de.fg' res = requests.get(url) 一般來說,res應該會回傳一個status code 用來判斷server的回應狀態 目前寫的爬蟲,若該網址掛掉 or 不存在, requests.get(url) 會直接噴一樣的 ERROR,造成程式終止 而不會回傳一個適當的status code 想問這是bug 還是 本來就這樣設計? 還是要自己用try except做錯誤處理?? 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.130.138.229 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1540194260.A.7DF.html
AndCycle: 網址不存在就沒有server,沒有server你哪來 status code? 10/22 17:08
AndCycle: http status code 是對面 server 給的, 連不到就沒有 10/22 17:10
newton2009: Time out ? 10/22 17:48
lajji: try except 10/22 21:12
zo6596001: try except 10/22 22:15
XperiaZ6C: 沒東西要怎麼回傳,用try-except吧 10/23 02:19
nini200: 網路相關的一般都會加 try except 10/23 06:10
qxpbyd: https://preview.tinyurl.com/y745mlh3 10/23 14:02
qxpbyd: https://preview.tinyurl.com/jncj5gp 10/23 14:05