python语言爬虫爬取歌曲代码X

import requests

song_urls = [
“https://m804.music.126.net/20240915142147/4e01caa69abda60b165e185607805ee1/jdyyaac/obj/w5rDlsOJwrLDjj7CmsOj/30379084686/b56a/dbd5/39fc/792d87f5d7014bb78547ec3804eeaac5.m4a?authSecret=00000191f441535c12810a3b1db72190”,
“https://m703.music.126.net/20240915140140/670dfe5c0144991d4cb778d6662fd762/jd-musicrep-privatecloud-audio-public/obj/woHCgMKXw6XCmDjDj8Oj/25248341156/6dae/5c8c/bac0/44dd85d2d2823b02090dd1a0b4dcad20.mp3”,
“https://m8.music.126.net/20240915141201/279c2e6ad1a64bc81f24b63d865fba37/ymusic/MTE4Njg2MjQwMw==/7934cef2a6038b3bf4d834db9b5334dc.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}”)

python语言爬虫爬取歌曲代码X_第1张图片

python语言爬虫爬取歌曲代码X_第2张图片

你可能感兴趣的:(python,爬虫,java)