How can i find a file size on the web ?

2007-12-02 Thread Abandoned
Hi..
Can i find a file size witdhout download?
For example: www.roche.com/rochea_z_sp.pdf
How can i find its size with python ?
I'm sorry for my bad english.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can i find a file size on the web ?

2007-12-02 Thread Dan Upton
On Dec 2, 2007 11:55 AM, Abandoned [EMAIL PROTECTED] wrote:
 Hi..
 Can i find a file size witdhout download?
 For example: www.roche.com/rochea_z_sp.pdf
 How can i find its size with python ?


When you send an HTTP request, most servers will respond with the
content length.  For instance, if you go to http://web-sniffer.net/,
you can type in the file you want to view and you can see the header
sent and received, and for the example you gave, you'll notice the
HTTP Response Header includes a line

Content-Length: 4054802

That should be the information you're looking for.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can i find a file size on the web ?

2007-12-02 Thread Adonis Vargas
Abandoned wrote:
 Hi..
 Can i find a file size witdhout download?
 For example: www.roche.com/rochea_z_sp.pdf
 How can i find its size with python ?
 I'm sorry for my bad english.

Typically you would just do an HTTP HEAD request in order to get 
information about the file without downloading it, but I tested the 
given site and it does not seem to support the HEAD request. Instead I 
used the GET request and read the headers in which contains information 
regarding the file as well, but opted no to read the data to avoid 
downloading it.

import httplib
connection = httplib.HTTPConnection(www.roche.com)
connection.request(GET, /rochea_z_sp.pdf)
response = connection.getresponse()
print response.status, response.reason
print File sie: %s % response.getheader('content-length')

Also you can do:

import urllib
response = urllib.urlopen(http://www.roche.com/rochea_z_sp.pdf;)
print response.info()

Hope this helps.

Adonis Vargas
-- 
http://mail.python.org/mailman/listinfo/python-list