以某狗音乐为例

import requestsimport reimport timeimport hashlibdef GetResponse(url):# 模拟浏览器headers ={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0'}# 发送请求response = requests.get(url=url,headers=headers)# 返回内容return responsedef GetInfo():# 请求网址link='https://wwwapi.kugou.com/play/songinfo?srcappid=2919&clientver=20000&clienttime=1709645100257&mid=99fdc9044912dc3185ee58da1a9f87d0&uuid=99fdc9044912dc3185ee58da1a9f87d0&dfid=3exBpJ2WlTHO4N287r0necyx&appid=1014&platid=4&encode_album_audio_id=9oevti38&token=2544e791bc15f255e8737748178f76680a2205d03c2259e2fc4892e9aa500045&userid=2195647882&signature=a6efee3c478d7a625553ab35eb149df9'JsonData = GetResponse(url=link).json()# 提取歌曲链接play_url = JsonData['data']['play_url']# 提取歌名audio_name = JsonData['data']['audio_name']# 获取数据return audio_name,play_urldef Save(title,url):# 对歌曲链接发送请求music_data = GetResponse(url=url).content# wb 保存模式with open("D:/music/{}.mp3".format(title), mode='wb') as f:f.write(music_data)if __name__ == '__main__':audio_name,play_url = GetInfo()Save(audio_name,play_url)print(audio_name,'保存成功!!')

修改User-Agent,link,保存地址即可。