分享一个 Python爬取酷我VIP音乐
请大家通过正规渠道开通vip,这里仅供学习,您使用后的一切后果与本站无关
用到的模块 requests模块(安装 pip install requests)
大概思路:
1.分析数据来源
2.发送请求
3.获取数据
4.解析数据
import requests
url="http://www.kuwo.cn/api/www/search/searchMusicBykeyWord"
singer=input("请输入歌手或歌名")
headers={
"Accept": "application/json, text/plain, */*",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.9",
"Cookie": "Hm_lvt_cdb524f42f0ce19b169a8071123a4797=1675060886; _ga=GA1.2.200062221.1675060887; _gid=GA1.2.1633576230.1675060887; _gat=1; Hm_lpvt_cdb524f42f0ce19b169a8071123a4797=1675062277; kw_token=C7GYBKZ1EIP",
"csrf": "C7GYBKZ1EIP",
"Host": "www.kuwo.cn",
"Referer": "http://www.kuwo.cn/search/list?key=%E5%91%A8%E6%9D%B0%E4%BC%A6",
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36",
}
par={
"key": singer,
"pn": 1,
"rn": 30,
"httpsStatus": 1,
"reqId": "625bd110-a06c-11ed-80e8-314b19858f45"
}
data=requests.get(url=url,headers=headers,params=par).json()
music_list=data['data']['list']
for listss in music_list:
#print(listss)
rid_list=listss['rid']
url_json=requests.get(url=f"http://www.kuwo.cn/api/v1/www/music/playUrl?mid={rid_list}&type=convert_url").json()
print(listss['name'])
print(url_json['data']['url'])
版权说明
文章采用: 《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权。版权声明:未标注转载均为本站原创,转载时请以链接形式注明文章出处。如有侵权、不妥之处,请联系站长删除。敬请谅解!