1.info()
这个是返回对象的字典对象,通常是服务器发送的特定的头。
import urllib.request
url="https://www.baidu.com"
respose=urllib.request.urlopen(url)
html_doc=respose.read().decode("utf-8")
print(respose.info())
运行结果:
C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\python.exe C:/Users/Administrator/PycharmProjects/untitled2/1-2.py
Accept-Ranges: bytes
Cache-Control: no-cache
Content-Length: 227
Content-Type: text/html
Date: Mon, 06 Aug 2018 05:45:03 GMT
Etag: "5b56b4a8-e3"
Last-Modified: Tue, 24 Jul 2018 05:10:00 GMT
P3p: CP=" OTI DSP COR IVA OUR IND COM "
Pragma: no-cache
Server: BWS/1.1
Set-Cookie: BD_NOT_HTTPS=1; path=/; Max-Age=300
Set-Cookie: BIDUPSID=FFBC03A7700100FA1362A08E8B484D6C; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
Set-Cookie: PSTM=1533534303; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
Strict-Transport-Security: max-age=0
X-Ua-Compatible: IE=Edge,chrome=1
Connection: clos
2. geturl()
import urllib.request
url="https://www.baidu.com/"
respose=urllib.request.urlopen(url)
print(respose.geturl())
运行结果:
C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\python.exe C:/Users/Administrator/PycharmProjects/untitled2/1-3.py
https://www.baidu.com/
Process finished with exit code 0