Downloading files off Interet
carroll at tjc.com
Tue Jan 6 11:13:26 CET 2004
On 5 Jan 2004 23:32:53 -0800, blaktyger at hotmail.com (Blaktyger) wrote:
>I would like to download some mp3 files from a web site. There is to
>much of them and I had the idea of writing a script to do it for me.
>f = urllib.urlopen(""" http://www.somemp3site.com/somemp3.com""")
>I ran the program and the file is not playing.
>Can someone help me?
A couple possibilities:
First, are you running on Windows? If so, you want your output file
Second, what does your output file look like? See if it's a text error
message. Some sites will check to see whether there is a referring page
from their own web site, and disallow transfer otherwise (or divert to a
different site). If your somemp3site.com site does that, your download
The only way I know around this is to give up using urllib, and use
urllib2 instead, opening a Request rather than the url directly, and
specifying the referring page from which you picked up the URL to the MP3
I can give more detail on this, but check the binary open first.
Also, if the referring page is not the issue, you will probably find it
much simpler to use urlretrieve instead. See
f = urllib.urlopen(""" http://www.somemp3site.com/somemp3.com""")
You just do:
That's it. It's almost cheating.
Unfortunately, there's no urllib2.urlretrieve, so if that referring page
thing is your issue, you can't use urlretrieve.
Hope this helps.
More information about the Python-list