[Tutor] Downloading Files from the net

Mark Tolonen metolone+gmane at gmail.com
Sun Sep 28 21:14:54 CEST 2008


"Timo" <timovwb at gmail.com> wrote in message 
news:48dfb602.2283420a.7dff.2f6f at mx.google.com...
> What is the best/correct way to download files from a webpage?
>
> www.example.com/example.mp3 for instance.
>
> I know how to open the site (with urllib), but have no idea how to write 
> the file to the harddisk.

Quick and dirty, if example.mp3 isn't too big to fit in memory at once:

import urllib
fin = urllib.urlopen('http://www.example.com/example.mp3')
fout = open('example.mp3','wb')
fout.write(fin.read())
fin.close()
fout.close()

-Mark




More information about the Tutor mailing list