防止爬取网页陷入死循环,python超时处理

超时处理`

#@File : testUrllib.py
#@Software : PyCharm
import urllib.request
#超时处理
try:
    response=urllib.request.urlopen("http://httpbin.org/get",timeout=0.1)
    print(response.read().decode("utf-8"))
except urllib.error.URLError as e:
    print("超时啦!")

原创文章 7 获赞 7 访问量 216

猜你喜欢

转载自blog.csdn.net/qq_44741960/article/details/106139535
今日推荐