0
点赞
收藏
分享

微信扫一扫

Python学习笔记(26)~爬虫基础学习:超时处理


超时处理

Demo

#!/usr/bin/python3
import urllib.request,urllib.error,urllib.parse

#超时处理
#timeout:时间门限,响应时间超过此门限,则视为超时
try:
response=urllib.request.urlopen("http://httpbin.org/get",timeout=1)
print(response.read().decode("utf-8"))
except urllib.error.URLError as e:
print("超时!!!")

运行结果

Python学习笔记(26)~爬虫基础学习:超时处理_爬虫


举报

相关推荐

0 条评论