|
- import requests
- import json
- import os
- UA伪装 = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36',
- 'Referer': 'http://www.kuwo.cn/search/list?key=%E5%91%A8%E6%9D%B0%E4%BC%A6',
- 'csrf': 'RUJ53PGJ4ZD',
- 'Cookie': 'Hm_lvt_cdb524f42f0ce19b169a8071123a4797=1577029678,1577034191,1577034210,1577076651; Hm_lpvt_cdb524f42f0ce19b169a8071123a4797=1577080777; kw_token=RUJ53PGJ4ZD'
- }
- 歌手名称 = input('请输入要下载的歌手:')
- 页数 = int(input('请输入歌曲页数:'))
- if not os.path.exists(f'c:/{歌手名称}'):
- os.mkdir(f'c:/{歌手名称}')
- # 1.拿到每一页歌曲名和歌曲编码
- for i in range(1,页数+1):
- 网址 = f'http://www.kuwo.cn/api/www/search/searchMusicBykeyWord?key={歌手名称}&pn={页数}&rn=30&httpsStatus=1&reqId=33ba4d30-c8fd-11ea-9573-05c2a88c5861'
- 响应数据 = requests.get(url=网址,headers=UA伪装).text
- 字典 = json.loads(响应数据)
- 列表 = 字典['data']['list']
- for i in 列表:
- 编码 = i['rid']
- 歌名 = i['name']
- # 2.拿到每个歌曲的下载地址
- 网址 = f'http://www.kuwo.cn/url?format=mp3&rid={编码}&response=url&type=convert_url3&br=128kmp3&from=web&t=1595083872654&httpsStatus=1&reqId=1faba1f1-c906-11ea-afb8-414f0829f1f1'
- 响应数据 = requests.get(url=网址,headers=UA伪装).text
- 字典 = json.loads(响应数据)
- # print(字典)
- 下载地址 = 字典['url']
- mp3 = requests.get(url=下载地址).content
- 路径 = f'c:/{歌手名称}/{歌名}.mp3'
- with open (路径,'wb') as 变量名:
- 变量名.write(mp3)
- print(歌名,"下载完成!!!")
复制代码
|
|