1 import sys, urllib2 2 # req = urllib2.Request(sys.argv[1]) 3 req = urllib2.Request(‘http://www.sina.com.cn‘) 4 fd = urllib2.urlopen(req) 5 print "Retrieved", fd.geturl() 6 info = fd.info() 7 for key, value in info.items(): 8 print "%s = %s" % (key, value)
结果如下:
Retrieved http://www.sina.com.cn content-length = 117199 x-cache = HIT from cnc.sy.1cf2.32.spool.sina.com.cn x-powered-by = shci_v1.03 content-encoding = gzip age = 3 expires = Mon, 28 Dec 2015 13:59:14 GMT vary = Accept-Encoding server = nginx last-modified = Mon, 28 Dec 2015 13:57:24 GMT connection = close cache-control = max-age=60 date = Mon, 28 Dec 2015 13:58:14 GMT content-type = text/html
时间: 2024-10-14 00:37:28