利用urllib2获取请求头部信息

示例为获取百度服务器请求头部信息:

>>> import urllib2
>>> re = urllib2.urlopen('http://www.baidu.com/')
>>> print re.headers
Date: Sun, 30 Jan 2011 08:47:57 GMT

Server: BWS/1.0

Content-Length: 7841

Content-Type: text/html;charset=gb2312

Cache-Control: private

Expires: Sun, 30 Jan 2011 08:47:57 GMT

Set-Cookie: BAIDUID=1456B286B54B8F94292CC53C3DBD0A28:FG=1; expires=Sun, 30-Jan-41 08:47:57 GMT; path=/; domain=.baidu.com

P3P: CP=" OTI DSP COR IVA OUR IND COM "

Connection: Close

posted @ 2011-01-30 16:52  软践  阅读(2208)  评论(0编辑  收藏  举报