import requests
song_urls = [
“http://music.163.com/song/media/outer/url?id=25795016.mp3”,
“http://music.163.com/song/media/outer/url?id=5255631.mp3”,
“http://music.163.com/song/media/outer/url?id=5255640.mp3”
]
for index, song_url in enumerate(song_urls):
response = requests.get(song_url, stream=True)
if response.status_code == 200:
with open(f"downloaded_song_{index + 1}.mp3", “wb”) as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)
print(f"歌曲 {index + 1} 下载成功!")
else:
print(f"请求歌曲 {index + 1} 失败,状态码:{response.status_code}")