python爬取QQ音乐评论信息
- python爬取QQ音乐评论信息
-
- 1.随便选个音乐
python爬取QQ音乐评论信息
1.随便选个音乐
https://y.qq.com/n/yqq/song/0039MnYb0qxYhV.html
当前的后台调试页面显示如下:
找到评论的数据接口:
https://c.y.qq.com/base/fcgi-bin/fcg_global_comment_h5.fcg?g_tk_new_20200303=1728726093&g_tk=1728726093&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=GB2312¬ice=0&platform=yqq.json&needNewCode=0&cid=205360772&reqtype=2&biztype=1&topid=97773&cmd=8&needmusiccrit=0&pagenum=0&pagesize=25&lasthotcommentid=&domain=qq.com&ct=24&cv=10101010
参数列表:
参数名 | 参数值 |
---|---|
g_tk_new_20200303 | 1728726093 |
g_tk | 1728726093 |
loginUin | 0 |
hostUin | 0 |
format | json |
inCharset | utf8 |
outCharset | GB2312 |
notice | 0 |
platform | yqq.json |
needNewCode | 0 |
cid | 205360772 |
reqtype | 2 |
biztype | 1 |
topid | 97773 |
cmd | 8 |
needmusiccrit | 0 |
pagenum | 0 |
pagesize | 25 |
lasthotcommentid | |
domain | qq.com |
ct | 24 |
cv | 10101010 |
可以发现g_tk_new_20200303和g_tk两者值相等,都是1728726093 |
- g_tk函数介绍
在百度后才知道 g_tk 是个加密函数 ,而且还是javascript写的
然后再所有 js 中搜索 g_tk 按 Ctrl +F
终于找到了
d 引用的是 cookie.js
https://y.gtimg.cn/music/portal/js/common/music/cookie.js
代码:
define("js/common/music/cookie.js", function(e, t, n) {
var o = e("js/common/config.js"),
i = {
set: function(e, t, n, i, c) {
if (c) {
var r = new Date;
r.setTime(r.getTime() + 36e5 * c)
}
return document.cookie = e + "=" + escape(t) + "; " + (c ? "expires=" + r.toGMTString() + "; " : "") + (i ? "path=" + i + "; " : "path=/; ") + (n ? "domain=" + n + ";" : "domain=" + o.DCCookieDomain + ";"), !0
},
get: function(e) {
var t;
return function(e) {
if (!e) return e;
for (; e != unescape(e);) e = unescape(e);
for (var t = ["<", ">", "'"