Downloading files off Interet

Michael Geary Mike at DeleteThis.Geary.com
Tue Jan 6 03:57:05 EST 2004


> Blaktyger wrote:
> B> I would like to download some mp3 files from a web site.
> B> There is to much of them and I had the idea of writing a
> B> script to do it for me.
>
> B> Code:
> B> import string
> B> import urllib
>
> B> f = urllib.urlopen(""" http://www.somemp3site.com/somemp3.com""")
>
> B> fic=open('mp3file.mp3','w')
> B> fic.write(f.read())
> B> fic.close()
> B> f.close()
>
> B> I ran the program and the file is not playing.
> B> Can someone help me?
> B> Thanks

Egor Bolonev wrote:
> may be devas esti wb
> fic=open('mp3file.mp3','wb')

Or, as someone pointed out when I posted similar code a while back, you can
do the whole thing with a single call:

import urllib
urllib.urlretrieve( 'http://www.foo.com/bar.mp3', 'bar.mp3' )

See the documentation for urllib.urlretrieve for additional information,
especially the optional reporthook argument that lets you provide a callback
function so you can display the progress for a long file.

-Mike





More information about the Python-list mailing list