标签:style blog http io ar color os sp on
主要给出两个版本,一个是通过 urllib 实现的,另一个是通过 urllib2 实现的,此为第二种,代码及实例如下:
>>> import urllib2 >>> from urllib2 import * >>> webUrl = "http://www.baidu.com" >>> doc = urllib2.urlopen(webUrl) >>> print doc.info() #或 doc.headers
打印信息
Date: Mon, 24 Nov 2014 07:22:07 GMT Content-Type: text/html; charset=utf-8 Transfer-Encoding: chunked Connection: Close Vary: Accept-Encoding Set-Cookie: BAIDUID=6F43AAA51E609EB80D9C0A18BB11720D:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com Set-Cookie: BAIDUPSID=6F43AAA51E609EB80D9C0A18BB11720D; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com Set-Cookie: BDSVRTM=0; path=/ Set-Cookie: BD_HOME=0; path=/ Set-Cookie: H_PS_PSSID=7931_10161_1433_7800_9452_10120_10016_9499_10051_10065_9967_9769_9105_9757_10007_9979_9024; path=/; domain=.baidu.com P3P: CP=" OTI DSP COR IVA OUR IND COM " Cache-Control: private Cxy_all: baidu+86091fc3efbc80d96c839cee1b7a0a36 Expires: Mon, 24 Nov 2014 07:21:28 GMT X-Powered-By: HPHP Server: BWS/1.1 BDPAGETYPE: 1 BDQID: 0xcf6e6ab100002443 BDUSERID: 0
标签:style blog http io ar color os sp on
原文地址:http://www.cnblogs.com/yu-zhang/p/4119250.html