美文网首页Python
Python urllib-error模块

Python urllib-error模块

作者: 大狗熊熊熊熊熊 | 来源:发表于2022-07-31 16:56 被阅读0次
    urllib.error模块常用类有
    1.urllib.error.URLError《处理URL程序异常》
      例:
      try:
          result = urllib.request.urlopen("https://www.bilibili.com/404")
      except urllib.error.URLError as e:
          print(e.reason)
    2.urllib.error.HTTPError 《处理http请求异常》
      例:
      try:
          result = urllib.request.urlopen("https://www.bilibili.com/404")
      except urllib.error.HTTPError as e:
          print(e.reason,e.code,e.headers,sep="\n")
      except urllib.error.URLError as e:
          print(e.reason)
      else:
          print("request successfully")
    

    相关文章

      网友评论

        本文标题:Python urllib-error模块

        本文链接:https://www.haomeiwen.com/subject/bnikwrtx.html