酷我音乐爬虫(400多行代码)
酷我⾳乐爬⾍(400多⾏代码)
酷我⾳乐
1. 分析⾳乐下载的接⼝
{
"format":"mp3",# ⾳频格式
"rid":"81010978",# ⾳乐的id
"response":"url",
"type":"convert_url3",
"br":"128kmp3",
"from":"web",# 来源
"t":"15840xxxxx60779",# 时间戳
"reqId":"xxxxxxxxxxxxxxxxxx",# 请求id
如何下载歌曲到mp3}
下⾯这是响应的json数据
{"code": 200, "msg": "success", "url": "sz-sycdn.kuwo/96f635b8ea7045ffe7f1dec9baa4cf4d/5e6a0115/resource/n1/68/38/37304574.mp3"}
请求返回了⼀个json数据,从这⾥我们可以看到,该**⾳乐id**对应的请求的url,由于可以在新的标签页打开这个请求,可以看出这⾥的请求反爬⼏乎没有
2. 分析如何获取歌曲的rid值
2.1 根据关键字获取rid值
2.2 通过获取⾳乐列表的接⼝获取rid值
这个接⼝需要cookie头和csrf头,从浏览器copy⼀下就可以了(应该是⽐较cookie⾥⾯的csrf值和csrf头⾥⾯的值是否相同)
{
"bangId":"93",# 酷我飙升榜
"pn":"1",# 页数
"rn":"30",# ⼀页的歌曲数
"reqId":"xxxxxxxxxxxxxxxxxx",# 请求的id
}
由于获取⾳乐列表是通过bangid获取,所以要到获取bangid的接⼝
2.3 获取所有的⾳乐排⾏榜的接⼝
这个接⼝⾥⾯的sourceid就对应了bangid值
这个接⼝需要cookie头和csrf头,从浏览器copy⼀下就可以了(应该是⽐较cookie⾥⾯的csrf值和csrf头⾥⾯的值是否相同),就是处理⼀下csrf,直接访问会出现{"success":false,"message":"CSRF Token Not Found!","now":"2020-03-xxx:00:xxx"}
来⼀张图
从这⾥,我们可以算⼀下,如果每⼀个⼦榜单下载前30⾸歌那么⼀共下载的歌曲数⽬为:
⼦榜单数⽬: 5 + 13 + 6 + 5 + 9 + 2 = 40
歌曲总数: 40 * 30 = 1200
每⾸歌曲的⼤⼩⼤约为: 4M
整个下下来的数据的⼤⼩为: 4800M = 4800/1024~= 4.69G
3. ⼀些其他的接⼝
3.1 根据⾳乐mid值获取⾳乐信息
这个接⼝需要剔除的参数很少,就⼀个reqid应该是标识的⾝份信息
{
"mid":"81010978",# ⾳乐的mid值和 rid 相同
"reqId":"xxxxxxxxxxxxxxxxxx",# 请求的id
}
这个接⼝需要cookie头和csrf头,从浏览器copy⼀下就可以了(应该是⽐较cookie⾥⾯的csrf值和csrf头⾥⾯的值是否相同)
3.2 获取歌词的接⼝
这个接⼝新建⼀个标签就可以访问了。
{"data":{"lrclist":[{"time":"0.0","lineLyric":"《你的答案》"},{"time":"2.46","lineLyric":"作词 Lyrics:林晨阳刘涛"},{"time":"4.69","lineLyric":"作曲 Music:刘涛"},{"t ime":"7.34","lineLyric":"演唱Singer:阿冗"},{"time":"9.32","lineLyric":"制作⼈ Produced by 刘涛"},{"time":"12.09","lineLyric":"编曲 Arranger:谭侃侃"},{"time":"
14.6","lineLyric":"吉他 Guitar:谭侃侃"},{"time":"15.15","lineLyric":"键盘 Keyboards:谭侃侃"},{"time":"17.44","lineLyric":"合声 Backing vocals:⾦天胡阁"},{" time":"18.95","lineLyric":"录⾳棚 Recording studio:北京好乐⽆荒录⾳棚"},{"time":"19.65","lineLyric":"录⾳师 Recording Engineer:吴佳敏"},{"time":"20.35","li neLyric":"混⾳师 Mixing Engineer:刘三⽄"},{"time":"21.59","lineLyric":"母带后期混⾳师 Mastering Engineer:刘三⽄"},{"time":"22.2","lineLyric":"监制 Executi ve producer: 陶诗"},{"time
":"23.0","lineLyric":"OP/SP:好乐⽆荒"},{"time":"24.0","lineLyric":"封⾯设计:kidult."},{"time":"24.82","lineLyric":"鸣谢:万物体验家;不要⾳乐"},{"time":"25.24","lineLyric":"也许世界就这样"},{"time":"28.49","lineLyric":"我也还在路上"},{"time":"31.13","lineLyric":"没有⼈能诉说"},{"time":"36.21 ","lineLyric":"也许我只能沉默"},{"time":"39.25","lineLyric":"眼泪湿润眼眶"},{"time":"42.1","lineLyric":"可⼜不⽢懦弱"},...
4. 写业务代码

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。