iwant to download a file with the urllib2, and meanwhile i want to display a progress bar.. but how can i get the actual downloaded filesize?
my current code is
ul = urllib2.urlopen('www.file.com/blafoo.iso')
data = ul.get_data()
or
open('file.iso', 'w').write(ul.read())
The data is first written to the file, if the whole download is recieved from the website. how can i access the downloaded data size?
Thanks for your help
You can use
info
function of urllib2 which returnsthe meta-information of the page
and than you can usegetheaders
to accessContent-Length
.For example, let's calculate the download size of
Ubuntu 12.04 ISO
Here's an example of a text progress bar using the awesome requests library and the progressbar library:
This is what I see in the console while running:
Edit: some notes: