酷我音乐获取

import requests

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36',
    'Cookie': '_ga=GA1.2.466145602.1585653284; _gid=GA1.2.839707421.1585653284; Hm_lvt_cdb524f42f0ce19b169a8071123a4797=1585653284,1585698391; Hm_lpvt_cdb524f42f0ce19b169a8071123a4797=1585698391; _gat=1; kw_token=UVJVC5WE3FF',
    'Referer': 'http://www.kuwo.cn/search/list?key=%E5%91%A8%E6%9D%B0%E4%BC%A6',  #  来源(从哪里来)
    'csrf': 'UVJVC5WE3FF',  #  密链
}


def get_musics(sing_rid,sing_name):
    url_2 = 'http://www.kuwo.cn/url?format=mp3&rid={}&response=url&type=convert_url3&br=128kmp3&from=web&t=1585698406673&reqId=e2030f20-73a9-11ea-b357-51d7f65d1873'.format(sing_rid)
    resp_2 = requests.get(url_2,headers=headers).json()
    musics_url = resp_2["url"]
    misics_resp = requests.get(musics_url,headers=headers)
    path = r'C:\Users\DELL\Desktop\python_wd\shipin\酷我音乐\{}.mp3'.format(sing_name)
    print("========正在下载  {}歌曲========".format(sing_name))
    with open(path,'wb')as f:
        f.write(misics_resp.content)




def main():
    singer = input("请输入歌手名字:")
    number = int(input("输入想要获取的页数:"))
    for i in range(1,number + 1):
        url = 'http://www.kuwo.cn/api/www/search/searchMusicBykeyWord?key={}&pn={}&rn=30&reqId=2eb713c0-7341-11ea-b404-7dadb3c0afa8'.format(singer,i)
        resp = requests.get(url,headers=headers).json()
        data = resp["data"]["list"]
        for a in data:
            sing_rid = a["rid"]
            sing_name = a["name"]
            get_musics(sing_rid,sing_name)



if __name__ == '__main__':
    main()




你可能感兴趣的:(音频数据)