[Tutor] downloading from a list

orbitz orbitz at ezabel.com
Mon Jul 5 18:05:26 CEST 2004


Why don't you just use the incredibly clever urllib module that you are 
already using?

By the way you probably should be usign urllib2

python at kc.rr.com wrote:

> Hi, all. Still a Python newbie and messing around with urllib at the 
> moment. Here's the particulars...
>
> I'm attempting to come up with a script which will download the mp3's 
> listed in a .m3u (playlist) file[1]. The heavy lifting is already done 
> and the script, as it stands looks like so:
>
> import os, urllib
>
> # ask for a url here...
> print "enter the URL you want to download something from:"
> # get the url and assign to 'url' variable
> url = raw_input()
> # declare the app to download with
> downloader = '/sw/bin/wget '
> # parse each line from the .m3u file
> for line in urllib.urlopen(url).readlines():
> # tell the system to use wget to download each item in the list
>     os.system (downloader + line)
> # be polite like mom said
> print "All done. Enjoy!"
>
> I was wondering, however, if there was any way for Python to just do 
> all the magic itself without relying on an outside application (like 
> wget), sorta like:
>
> import os, urllib
>
> print "enter the URL you want to download something from:"
> url = raw_input()
> for line in urllib.urlopen(url).readlines():
>     # something incredibly clever right about here!
> print "All done. Enjoy!"
>
> I didn't see anything, but it's getting rather late (0500 CST) and I'm 
> feeling sleepy. Any hints on how to download those items in a list 
> without relying on an external application?
>
> Many thanks for a hint or two!
>
> tom
>
> [1] Lots of musicians encourage downloading their tracks, just 
> automating it a bit for personal use and to stretch my python wings 
> tad. Check out magnatune.com for all sorts of musical goodness.
>
> Weinberg's Law:
>
> "If builders built buildings the way programmers wrote programs, then 
> the first woodpecker that came along would destroy civilization"
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>




More information about the Tutor mailing list