Using the returned-urllib-object method info()
, you can get various information on the retrivedretrieved document. Example of grabbing the current Google logo:
>>> import urllib
>>> d = urllib.urlopen("http://www.google.co.uk/logos/olympics08_opening.gif")
>>> print d.info()
Content-Type: image/gif
Last-Modified: Thu, 07 Aug 2008 16:20:19 GMT
Expires: Sun, 17 Jan 2038 19:14:07 GMT
Cache-Control: public
Date: Fri, 08 Aug 2008 13:40:41 GMT
Server: gws
Content-Length: 20172
Connection: Close
It's a dict, so to get the size of the file, you do urllibobject.info()['Content-Length']
print f.info()['Content-Length']
And to get the size of the local file (for comparison), you can use the os.stat() command:
os.stat("/the/local/file.zip").st_size