首页 > 代码库 > 获取http请求的响应状态

获取http请求的响应状态

import urllib.request
url="http://www.baidu.com"
 
#返回一个对象
response=urllib.request.urlopen(url)
 
#打印出远程服务器返回的header信息
print(response.info())
 
#打印出来访问的网址
print(response.geturl())
 
#打印出来http的状态,200就证明正常
print(response.getcode())

结果

================================ RESTART ================================
>>>
Date: Mon, 06 Feb 2017 02:30:35 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: close
Set-Cookie: acw_tc=AQAAAJEDMgEk0goAL5LxZaUpgobKV1cj; Path=/; HttpOnly
Server: nginx
Vary: Accept-Encoding
ETag: "30407f-11c5-4d29f74cbf800"
Accept-Ranges: bytes
 
 
http://www.baidu.com
200
>>>

 

获取http请求的响应状态