python爬虫爬取网易云音乐程序代码ZQ

import requests
import os

def download_video(url, save_path):
response = requests.get(url, stream=True)
if response.status_code == 200:
with open(save_path, ‘wb’) as file:
for chunk in response.iter_content(chunk_size=8192):
file.write(chunk)
print(f"音频下载成功,保存路径为:{save_path}“)
else:
print(f"无法下载音频,状态码:{response.status_code}”)

音频的请求 URL

video_url = “https://m703.music.126.net/20240922151633/1ac0eb77b0cfe0f8b291b0a13e779d32/jd-musicrep-privatecloud-audio-public/obj/woHCgMKXw6XCmDjDj8Oj/36387974826/a360/992e/85db/ff3bea30a16918d9b838203315ee5d41.mp3”

设置保存路径和文件名

save_directory = “C:\Users\Administrator\PycharmProjects\python测试 - 副本 (3)”
if not os.path.exists(save_directory):
os.makedirs(save_directory)
save_filename = “1.mp3”
save_path = os.path.join(save_directory, save_filename)

download_video(video_url, save_path)

网易云音乐

音频的请求 URL

video_url = “https://m703.music.126.net/20240922145031/d3fb631365bd98b896766f1b36f11601/jd-musicrep-privatecloud-audio-public/obj/woHCgMKXw6XCmDjDj8Oj/36387974826/a360/992e/85db/ff3bea30a16918d9b838203315ee5d41.mp3”

音频的请求 URL

video_url = “https://m704.music.126.net/20240922150158/3a15df713269693d48fde19644f193e7/jdyyaac/obj/w5rDlsOJwrLDjj7CmsOj/36509383374/80a2/fd38/3430/7ab5e38e0a2c954ddbb98d083879e951.m4a?authSecret=000001921872a2cb03760a3b1e1e4150”

音频的请求 URL

video_url = “https://m703.music.126.net/20240922151633/1ac0eb77b0cfe0f8b291b0a13e779d32/jd-musicrep-privatecloud-audio-public/obj/woHCgMKXw6XCmDjDj8Oj/36387974826/a360/992e/85db/ff3bea30a16918d9b838203315ee5d41.mp3”

https://m704.music.126.net/20240922154812/31aef0d39e7d5c0797fd1e8b844f9da9/jdymusic/obj/wo3DlMOGwrbDjj7DisKw/11542163634/cb36/2c6f/d1ec/f6d4968ccde729441bf3d4178bb524e4.mp3?authSecret=00000192189cf5aa020d0a3b1e501bee

你可能感兴趣的:(python,爬虫,开发语言)