gpt4 book ai didi

python - 在 python 中下载 .mp3 文件

转载 作者:行者123 更新时间:2023-11-28 17:43:53 26 4
gpt4 key购买 nike

<分区>

我正在尝试下载一个 .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())

有没有人可以告诉我我做错了什么以及我该如何解决?谢谢。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com