0
点赞
收藏
分享

微信扫一扫

python爬虫异常的处理方式

烟中雯城 2023-02-06 阅读 62


# coding=UTF-8

from urllib import request,error
try:
response = request.urlopen('http://cuiqingcai.com/index.html')
except error.URLError as e:
print(e.reason)
print(e.reason)



try:
response = request.urlopen('http://cuiqingcai.com/index.html')
except error.HTTPError as e:
print(e.reason,e.code,e.headers,sep='\n')
except error.URLError as e:
print(e.reason)
else :
print('Request Successfully')



try:
urllib.request.urlopen('http://httpbin.org/get', timeout=0.1)
except urllib.error.URLError as e:
if isinstance(e.reason, socket.timeout):
print('TIME OUT!!!')


举报

相关推荐

0 条评论