Question : urllib2 info()

Sorry if this is a stupid question, but I am a bit stuck.  I am using info() from urllib2.  It returns the metadata of the url.  I would like to print 'some' of this info to the screen, but I can't seem to get just what I want.  I would like to avoid re, but am prepared to use it if needed.

For example.  Calling info() on cnn.com produces this output:

ate: Sat, 04 Nov 2006 00:01:09 GMT
Server: Apache
Vary: Accept-Encoding,User-Agent
Cache-Control: max-age=60, private
Expires: Sat, 04 Nov 2006 00:02:01 GMT
Content-Type: text/html
Content-Length: 103933
Connection: close

How would I just get parts of it?  For example, just the Server and content-type.  Or the content length, expiration and ate?  I believe that info() returns a dict, but I am not sure.

Thanks,
Brian

Answer : urllib2 info()

info() actually returns an httplib.HTTPMessage.

http://doc.astro-wise.org/httplib.html#HTTPMessage

You can use the get function of the HTTPMessage to get any header by name.

>>> import urllib2
>>> response = urllib2.urlopen("http://www.experts-exchange.com/Programming/Programming_Languages/Python/Q_22048712.html")
>>> info = response.info()
>>> info.get("Server")
'Apache-Coyote/1.1'
Random Solutions  
 
programming4us programming4us