Python爬虫教程-09-error 模块
2021-07-04 20:12
标签:https print read orm 爬虫 == error: alt 连接 今天的主角是error,爬取的时候,很容易出现错,所以我们要在代码里做一些,常见错误的处,关于urllib.error Python爬虫教程-09-error 模块 标签:https print read orm 爬虫 == error: alt 连接 原文地址:https://www.cnblogs.com/xpwi/p/9600667.htmlPython爬虫教程-09-error模块
URLError
# 案例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)
HTTPError
URLError和HTTPError的区别:
- 本笔记不允许任何个人和组织转载