【发布时间】:2013-12-29 00:41:10
【问题描述】:
我正在尝试下载一个 .mp3 文件,但是,当我下载它时,它已被下载,但听起来像是通过我的扬声器发出的吱吱声和其他奇怪的噪音(类似于当您的 .mp3 文件在编码中有错误时) )。
这是我当前的代码:
# sets the song url to mp3link variable.
mp3link = dLink[0]
# opens the .mp3 file - using the same procedure as above.
openmp3 = open('testing.mp3', 'w')
dl = urllib2.urlopen(mp3link)
dl2 = dl.read()
# writes the .mp3 file to the file 'testing.mp3' which is in the variable openmp3.
openmp3.write(dl2)
openmp3.close()
print 'done'
我知道我可以将此代码用作更快的方法:
dlmp3 = urllib2.urlopen(url)
with open('testing2.mp3', 'wb') as filee:
filee.write(dlmp3.read())
有没有人可以告诉我我做错了什么以及如何解决它? 谢谢。
【问题讨论】: