[Python] python爬虫实例

 
3054 0
2085747573 2021-11-14 10:39:22 | 显示全部楼层 |阅读模式
from urllib import request
from urllib import error

# 第一种方法,URLErroe和HTTPError
def Err():
url = "https://segmentfault.com/zzz"
req = request.Request(url)

try:
response = request.urlopen(req)
html = response.read().decode("utf-8")
print(html)
except error.HTTPError as e:
print(e.code)
except error.URLError as e:
print(e.reason)

H.U.C-CI
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

2085747573

等待验证会员

关注
  • 14
    主题
  • 2
    粉丝
  • 1
    关注
计算机是一种很奇妙的东西,你不仔细去钻研,它恐怕比宇宙从什么时候诞生这个问题还难

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2025 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行