用python下载有两种方法,使用urllib,urllib2两个类
1.使用urllib的urlretrieve方法:
代码如下
import urllib
filename = " http://122.72.25.73/icache/bai-show.com/fileupload/music/634107480100781250.mp3 "
urllib.urlretrieve(filename,r " c:\urllib.mp3 " )
这样就会在c:\下有我们下载的urllib.mp3文件。
2。使用urllib2
import urllib2
url = " http://122.72.25.73/icache/bai-show.com/fileupload/music/634107480100781250.mp3 "
res = urllib2.urlopen(url)
data = res.read()
open(r " c:\urllib2.mp3 " , " wb " ).write(data)