How to do a Http HEAD requests
Fredrik Lundh
fredrik at pythonware.com
Tue Dec 12 09:34:12 EST 2006
Soni Bergraj wrote:
> I was just wondering if there is a more convenient way of doing a Http
> HEAD requests then the socket module?
quick version:
>>> import urllib2
>>> request = urllib2.Request("http://www.python.org")
>>> request.get_method = lambda: "HEAD"
>>> http_file = urllib2.urlopen(request)
>>> http_file.headers
<httplib.HTTPMessage instance at 0x00C711E8>
>>> http_file.headers["content-type"]
'text/html'
>>> print http_file.headers
Date: Tue, 12 Dec 2006 14:33:08 GMT
Server: Apache/2.0.54 (Debian GNU/Linux) DAV/2 SVN/1.1.4 mod_python/3.1.3 Python
/2.3.5 mod_ssl/2.0.54 OpenSSL/0.9.7e
Last-Modified: Tue, 12 Dec 2006 07:04:52 GMT
ETag: "61b82-2fd2-e60f4d00"
Accept-Ranges: bytes
Content-Length: 12242
Connection: close
Content-Type: text/html
</F>
More information about the Python-list
mailing list