因之前想写python爬虫判断douban的页面重定向,故写了以下代码,获取网页头部信息, 返回响应码
conn = httplib.HTTPConnection(host)
conn.request("GET",path)
return conn.getresponse().status
HTTPConnection.request(method, url[, body[, headers]])
代码中使用了"HEAD"的http请求方法,
故只会返回头信息,而不返回网页实体。
The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response.