1. 程式人生 > >Python 爬蟲03 urlopen 返回物件

Python 爬蟲03 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()