本帖最后由 ddvvc 于 2023-7-25 09:36 编辑
某狗榜首音乐可以下载未登录的音乐,如果想下其他榜单的歌曲,将link里面的url换成其他榜单链接
[Python] 纯文本查看 复制代码 import requests
import re
import os
link='https://www.kugou.com/yy/rank/home/1-6666.html?from=rank'
headers={'User-Agent':'xx'} #user-agent请换成自己浏览器的
response2=requests.get(url=link,headers=headers).text
eid =re.findall('data-index="\d+" data-eid="(.*?)"',response2)
for musicid in eid:
url = f'https://wwwapi.kugou.com/yy/index.php?r=play/getdata&callback&dfid=3MmYPK1TgvoY3ekNaJ45mjYH&appid=1014&mid=a51eace30575793fc6ad4f9e52fca686&platid=4&encode_album_audio_id={musicid}'
response = requests.get(url=url, headers=headers)
data_list = response.json()
audioname = data_list['data']['audio_name']
play_url = data_list['data']['play_url']
audioname = re.sub(r'[<>:"/\\|?*]', '_', audioname)
print(audioname, play_url)
music = requests.get(url=play_url, headers=headers).content
# 如果'kugou music'目录不存在,则创建该目录
if not os.path.exists('kugoumusic'):
os.makedirs('kugoumusic')
with open('kugoumusic\\' + audioname + '.mp3', 'wb') as f:
f.write(music)
|