获取http请求的响应状态
2021-06-08 16:03
标签:code 远程服务 www. url header open com == 请求 结果 获取http请求的响应状态 标签:code 远程服务 www. url header open com == 请求 原文地址:http://www.cnblogs.com/yrxns/p/7306417.htmlimport 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
>>>