标签:https print read orm 爬虫 == error: alt 连接
今天的主角是error,爬取的时候,很容易出现错,所以我们要在代码里做一些,常见错误的处,关于urllib.error
# 案例v9
# URLError的使用
from urllib import request,error
if __name__ == ‘__main__‘:
url = "http://www.baiiiiiiiiiiidu.com/"
try:
req = request.Request(url)
rsp = request.urlopen(req)
html = rsp.read().decode()
print(html)
except error.URLError as e:
print("URLError:{0}".format(e.reason))
print("URLError:{0}".format(e))
except Exception as e:
print(e)
标签:https print read orm 爬虫 == error: alt 连接
原文地址:https://www.cnblogs.com/xpwi/p/9600667.html