Python 爬虫02 urlopen 返回对象

urlopen 返回对象

  • geturl: 返回请求对象的 URL
  • info: 请求反馈对象的 meta 信息
  • getcode: 返回的 HTTP code

案例

from urllib import request
urls = "https://blog.csdn.net/xidianliutingting/article/details/53580569"
rsp = request.urlopen(urls)
print("url: {0}".format(rsp.geturl()))
print("info: {0}".format(rsp.info()))
print("Code: {0}".format(rsp.getcode()))
html = rsp.read()
htm = html.decode()

猜你喜欢

转载自blog.csdn.net/qq_15902869/article/details/80724350