好友
阅读权限10
听众
最后登录1970-1-1
|
Mrhe
发表于 2021-10-13 16:11
import requests
import re
import time
def Tools(url):
headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" "AppleWebKit/537.36 (KHTML, like Gecko)" "Chrome/94.0.4606.71 Safari/537.36 Edg/94.0.992.38"
}
response = requests.get(url, headers=headers)
return response
def Save(name,url):
mp3 = Tools(url).content #请求MP3地址链接 返回格式16进制
f = open("./kugou/{}.mp3".format(name),"wb")#w文件存在写入 不存在就创建 b进制读写
f.write(mp3)
f.close()
print("{}下载完成.......".format(name))
url = 'https://www.kugou.com/yy/html/rank.html'
response = Tools(url).text
# print(response)
album_id = re.findall(r'"album_id":(.*?),', response)
Hash = re.findall(r'"Hash":"(.*?)",', response)
# print(album_id)
# print(Hash)
for a, h in zip(album_id, Hash):
# 生成时间戳
time1 = int(time.time() * 1000)
# print(time1)
# 包含下载歌曲地址URL
urls = 'https://wwwapi.kugou.com/yy/index.php?r=play/getdata&hash={}&appid=1014&mid=5466a3fe42668debc4a044c5ba28dd2a&platid=4&album_id={}&_={}'.format(
h, a, time1)
# print(urls)
response1 = Tools(urls).json()
#print(response1)
audio_name = response1["data"]["audio_name"].split('-')[1]
play_url = response1["data"]["play_url"]
#print(audio_name,play_url)
Save(audio_name,play_url)
|
免费评分
-
查看全部评分
|
发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。 |
|
|
|
|