网易云音乐作为一款功能强大的音乐流媒体平台,为用户提供了丰富的音乐体验和社区互动。然而,当用户希望批量下载音乐资源,尤其是整个歌单或某位歌手的全部歌曲时,受限于版权保护和平台策略,官方渠道通常无法直接实现这一需求。在这种情况下,一些技术爱好者或开发者可能会转向使用爬虫技术来获取所需资源。
对于像网易云音乐这样通过加密请求参数(如 params 和 encSecKey)来保护数据的平台,逆向工程成为解析这些参数、编写有效爬虫的关键第一步。
一、定位加密位置
首先通过全局搜索 “params:”,使用冒号可以有效减少无关结果。接着,在每个疑似位置设置断点,然后刷新页面。这次运气不错,第一个搜索结果就命中了加密位置,唯一的遗憾是其他断点显得多余了。
断住的代码具体是:
var bVi6c = window.asrsea(JSON.stringify(i0x), bse6Y(["流泪", "强"]), bse6Y(Qu1x.md), bse6Y(["爱心", "女孩", "惊恐", "大笑"]));
e0x.data = j0x.cr1x({
params: bVi6c.encText,
encSecKey: bVi6c.encSecKey
})
分析后可知,window.asrsea
的参数分别是JSON.stringify(i0x),bse6Y(["流泪", "强"]),bse6Y(Qu1x.md),bse6Y(["爱心", "女孩", "惊恐", "大笑"])
,然后结果bVi6c是一个字典,其中有params和encSecKey的值。
尽管是大厂平台,但加密位置其实很好找到,甚至没有复杂的混淆处理。
二、算法分析
在var bVi6c = window.asrsea(JSON.stringify(i0x), bse6Y(["流泪", "强"]), bse6Y(Qu1x.md), bse6Y(["爱心", "女孩", "惊恐", "大笑"]));
这里设置断点,刷新或继续前进。由于会涉及多个请求,我们主要关注包含歌曲ID的那个请求,返回的就是对应歌曲的 m4a 地址。
经过一番努力,终于逐步定位到了i0x
的具体内容,如下。
i0x = {
"ids": "[2116798541]",
"level": "standard",
"encodeType": "aac",
"csrf_token": "fcbba2252c7cd7ad57af5c140eaec00f"
}
返回的就是我们要的音频网址,ids就是歌曲ID,这个歌曲ID的话在其他地方可以找到!
接下来需要分析传入 window.asrsea
的四个参数。第一个参数使用 JSON.stringify
,比较简单,就是将对象转换为字符串。后面三个参数则都涉及到 bse6Y
方法。那我们就来看看这个 bse6Y
方法究竟是如何工作的!
bse6Y(["流泪", "强"])
和bse6Y(["爱心", "女孩", "惊恐", "大笑"])
中的数组是写死的,打印出Qu1x.md的值(['色', '流感', '这边', '弱', '嘴唇', '亲', '开心', '呲牙', '憨笑', '猫', '皱眉', '幽灵', '蛋糕', '发怒', '大哭', '兔子', '星星', '钟情', '牵手', '公鸡', '爱意', '禁止', '狗', '亲亲', '叉', '礼物', '晕', '呆', '生病', '钻石', '拜', '怒', '示爱', '汗', '小鸡', '痛苦', '撇嘴', '惶恐', '口罩', '吐舌', '心碎', '生气', '可爱', '鬼脸', '跳舞', '男孩', '奸笑', '猪', '圈', '便便', '外星', '圣诞'])
,什么感觉?是不是好乱啊!但是只要你想到这个可能也是写死的,那就好办了。直接全局搜索任意词语,就比如“亲亲”,怎么样,多个文件里有一摸一样的!
所以这个要么是返回随机的,要么就是写死的(有可能是请求返回的,但是还是每次都一样,就算是不一样的,涉及这个请求应该是没有参数加密的,不然它加密用到的参数都没有怎么加密)。
所以接下来对bse6Y就有两种方法了,一个是继续扣算法,每次进行运算,得出结果,另外一个的话就是直接用结果。这里的话我就直接用结果了,实时证明这么做是可运行的。例如bse6Y([“流泪”, “强”])的结果就是’010001’,大家自己去得到后几个结果哈!
最后转入对window.asrsea的分析,看着是挺吓人的,还用上了window,但又一想,貌似又有一点像只会写全局变量的我,直接进去。
function d(d, e, f, g) {
var h = {}
, i = a(16);
return h.encText = b(d, g),
h.encText = b(h.encText, i),
h.encSecKey = c(i, e, f),
h
}
’
运行运行
创建一个空的h,一个I,encText 用b方法进行了两次加密,encSecKey则是用c方法,参数也有i。
先看看a是个什么,盲猜是个生成指定位数随机字符串的方法。
function a(a) {
var d, e, b = “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789”, c = “”;
for (d = 0; a > d; d += 1)
e = Math.random() * b.length,
e = Math.floor(e),
c += b.charAt(e);
return c
}
’
运行运行
都说了,包的呀!再看b方法,看看这又是什么方法。
function b(a, b) {
var c = CryptoJS.enc.Utf8.parse(b)
, d = CryptoJS.enc.Utf8.parse(“0102030405060708”)
, e = CryptoJS.enc.Utf8.parse(a)
, f = CryptoJS.AES.encrypt(e, c, {
iv: d,
mode: CryptoJS.mode.CBC
});
return f.toString()
}
’
运行运行
啊!这这这!这一CryptoJS一出也太亲切了吧,这也太惊喜了吧!这就破案了!那这c方法又会是?刚刚好就在旁边。
function c(a, b, c) {
var d, e;
return setMaxDigits(131),
d = new RSAKeyPair(b,“”,c),
e = encryptedString(d, a)
}
’
运行运行
真相大白了!很常规的加密方法!AES和RSA!
三、算法还原
1. 使用标准库调用 AES 算法
AES(Advanced Encryption Standard)是一种对称加密算法,也叫高级加密标准。它由美国国家标准与技术研究院(NIST)于 2001 年发布,用来替代 DES 算法。AES 支持 128 位、192 位或 256 位密钥进行数据加密和解密,具有高强度、快速和易于实现的特点。在本例中,我们直接通过标准库调用 AES 算法进行运算。
var CryptoJS = require("crypto-js")
function encrypt(a, b) {
var c = CryptoJS.enc.Utf8.parse(b)
, d = CryptoJS.enc.Utf8.parse("0102030405060708")
, e = CryptoJS.enc.Utf8.parse(a)
, f = CryptoJS.AES.encrypt(e, c, {
iv: d,
mode: CryptoJS.mode.CBC
});
return f.toString()
}
2. 还原 RSA 算法
“扣” 算法是指从网页文件中提取并还原算法,在本地环境运行出结果。首先,将 c 方法提取出来,根据“缺啥补啥”的原则进行补全。传入参数并调用时,通常会遇到类似 “xxx is not defined” 的错误,此时再去补齐相应的内容。常量需要补常量,方法需要补方法,直接通过搜索定位并补充即可。
function c(a, b, c) {
var d, e;
return setMaxDigits(131),
d = new RSAKeyPair(b,"",c),
e = encryptedString(d, a)
}
a = 'boBRdydPWcDp1S64'
b = '010001'
e = '00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7'
result = c(a,b,e)
console.log(result)
这时候你一运行肯定会报错,setMaxDigits is not defined,补就完了——在网页文件中直接到用到setMaxDigits那,进不去就打个断点,断到这就可以了!补的时候尽量把调用的方法和常量放到c方法前面。
function setMaxDigits(a) {
maxDigits = a,
ZERO_ARRAY = new Array(maxDigits);
for (var b = 0; b < ZERO_ARRAY.length; b++)
ZERO_ARRAY[b] = 0;
bigZero = new BigInt,
bigOne = new BigInt,
bigOne.digits[0] = 1
}
在补全代码后运行,如果仍然有缺失,继续补充,直到成功。如果觉得这个过程太慢,可以一次性把所有可疑文件中的方法都提取出来,以加快速度。不过我个人很享受逐步补全的过程,尤其是最终发现比全量提取少了许多无用代码时,特别有成就感。
当遇到 “Cannot read properties of undefined (reading ‘0’)” 错误时,可以在代码前加一条打印语句,检查输出结果,跟浏览器的结果对比,看看是否遗漏了什么。在这个例子中,highBitMasks、lowBitMasks 和 hexToChar 被重新赋值了一次,通过简单的关键字搜索就能定位这个问题。经过十分钟的调整,这些问题都得以解决,整个过程其实相对简单、重复性高,对于新手来说非常友好,是一次优雅的练习。接下来直接看代码吧。
var maxDigits, ZERO_ARRAY, bigZero, bigOne, dpl10, lr10, hexatrigesimalToChar, hexToChar, highBitMasks, lowBitMasks, biRadixBase = 2, biRadixBits = 16, bitsPerDigit = biRadixBits, biRadix = 65536, biHalfRadix = biRadix >>> 1, biRadixSquared = biRadix * biRadix, maxDigitVal = biRadix - 1, maxInteger = 9999999999999998;
highBitMasks = new Array(0,32768,49152,57344,61440,63488,64512,65024,65280,65408,65472,65504,65520,65528,65532,65534,65535);
lowBitMasks = new Array(0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535);
hexToChar = new Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"),
function biDivideByRadixPower(a, b) {
var c = new BigInt;
return arrayCopy(a.digits, b, c.digits, 0, c.digits.length - b),
c
}
function setMaxDigits(a) {
maxDigits = a,
ZERO_ARRAY = new Array(maxDigits);
for (var b = 0; b < ZERO_ARRAY.length; b++)
ZERO_ARRAY[b] = 0;
bigZero = new BigInt,
bigOne = new BigInt,
bigOne.digits[0] = 1
}
function BigInt(a) {
this.digits = "boolean" == typeof a && 1 == a ? null : ZERO_ARRAY.slice(0),
this.isNeg = !1
}
function RSAKeyPair(a, b, c) {
this.e = biFromHex(a),
this.d = biFromHex(b),
this.m = biFromHex(c),
this.chunkSize = 2 * biHighIndex(this.m),
this.radix = 16,
this.barrett = new BarrettMu(this.m)
}
function biFromHex(a) {
var d, e, b = new BigInt, c = a.length;
for (d = c,
e = 0; d > 0; d -= 4,
++e)
b.digits[e] = hexToDigit(a.substr(Math.max(d - 4, 0), Math.min(d, 4)));
return b
}
function hexToDigit(a) {
var d, b = 0, c = Math.min(a.length, 4);
for (d = 0; c > d; ++d)
b <<= 4,
b |= charToHex(a.charCodeAt(d));
return b
}
function charToHex(a) {
var h, b = 48, c = b + 9, d = 97, e = d + 25, f = 65, g = 90;
return h = a >= b && c >= a ? a - b : a >= f && g >= a ? 10 + a - f : a >= d && e >= a ? 10 + a - d : 0
}
function biHighIndex(a) {
for (var b = a.digits.length - 1; b > 0 && 0 == a.digits[b]; )
--b;
return b
}
function BarrettMu(a) {
this.modulus = biCopy(a),
this.k = biHighIndex(this.modulus) + 1;
var b = new BigInt;
b.digits[2 * this.k] = 1,
this.mu = biDivide(b, this.modulus),
this.bkplus1 = new BigInt,
this.bkplus1.digits[this.k + 1] = 1,
this.modulo = BarrettMu_modulo,
this.multiplyMod = BarrettMu_multiplyMod,
this.powMod = BarrettMu_powMod
}
function biCopy(a) {
var b = new BigInt(!0);
return b.digits = a.digits.slice(0),
b.isNeg = a.isNeg,
b
}
function biDivide(a, b) {
return biDivideModulo(a, b)[0]
}
function biDivideModulo(a, b) {
var f, g, h, i, j, k, l, m, n, o, p, q, r, s, c = biNumBits(a), d = biNumBits(b), e = b.isNeg;
if (d > c)
return a.isNeg ? (f = biCopy(bigOne),
f.isNeg = !b.isNeg,
a.isNeg = !1,
b.isNeg = !1,
g = biSubtract(b, a),
a.isNeg = !0,
b.isNeg = e) : (f = new BigInt,
g = biCopy(a)),
new Array(f,g);
for (f = new BigInt,
g = a,
h = Math.ceil(d / bitsPerDigit) - 1,
i = 0; b.digits[h] < biHalfRadix; )
b = biShiftLeft(b, 1),
++i,
++d,
h = Math.ceil(d / bitsPerDigit) - 1;
for (g = biShiftLeft(g, i),
c += i,
j = Math.ceil(c / bitsPerDigit) - 1,
k = biMultiplyByRadixPower(b, j - h); -1 != biCompare(g, k); )
++f.digits[j - h],
g = biSubtract(g, k);
for (l = j; l > h; --l) {
for (m = l >= g.digits.length ? 0 : g.digits[l],
n = l - 1 >= g.digits.length ? 0 : g.digits[l - 1],
o = l - 2 >= g.digits.length ? 0 : g.digits[l - 2],
p = h >= b.digits.length ? 0 : b.digits[h],
q = h - 1 >= b.digits.length ? 0 : b.digits[h - 1],
f.digits[l - h - 1] = m == p ? maxDigitVal : Math.floor((m * biRadix + n) / p),
r = f.digits[l - h - 1] * (p * biRadix + q),
s = m * biRadixSquared + (n * biRadix + o); r > s; )
--f.digits[l - h - 1],
r = f.digits[l - h - 1] * (p * biRadix | q),
s = m * biRadix * biRadix + (n * biRadix + o);
k = biMultiplyByRadixPower(b, l - h - 1),
g = biSubtract(g, biMultiplyDigit(k, f.digits[l - h - 1])),
g.isNeg && (g = biAdd(g, k),
--f.digits[l - h - 1])
}
return g = biShiftRight(g, i),
f.isNeg = a.isNeg != e,
a.isNeg && (f = e ? biAdd(f, bigOne) : biSubtract(f, bigOne),
b = biShiftRight(b, i),
g = biSubtract(b, g)),
0 == g.digits[0] && 0 == biHighIndex(g) && (g.isNeg = !1),
new Array(f,g)
}
function biShiftLeft(a, b) {
var e, f, g, h, c = Math.floor(b / bitsPerDigit), d = new BigInt;
for (arrayCopy(a.digits, 0, d.digits, c, d.digits.length - c),
e = b % bitsPerDigit,
f = bitsPerDigit - e,
g = d.digits.length - 1,
h = g - 1; g > 0; --g,
--h)
d.digits[g] = d.digits[g] << e & maxDigitVal | (d.digits[h] & highBitMasks[e]) >>> f;
return d.digits[0] = d.digits[g] << e & maxDigitVal,
d.isNeg = a.isNeg,
d
}
function biNumBits(a) {
var e, b = biHighIndex(a), c = a.digits[b], d = (b + 1) * bitsPerDigit;
for (e = d; e > d - bitsPerDigit && 0 == (32768 & c); --e)
c <<= 1;
return e
}
function arrayCopy(a, b, c, d, e) {
var g, h, f = Math.min(b + e, a.length);
for (g = b,
h = d; f > g; ++g,
++h)
c[h] = a[g]
}
function biMultiplyByRadixPower(a, b) {
var c = new BigInt;
return arrayCopy(a.digits, 0, c.digits, b, c.digits.length - b),
c
}
function biCompare(a, b) {
if (a.isNeg != b.isNeg)
return 1 - 2 * Number(a.isNeg);
for (var c = a.digits.length - 1; c >= 0; --c)
if (a.digits[c] != b.digits[c])
return a.isNeg ? 1 - 2 * Number(a.digits[c] > b.digits[c]) : 1 - 2 * Number(a.digits[c] < b.digits[c]);
return 0
}
function biSubtract(a, b) {
var c, d, e, f;
if (a.isNeg != b.isNeg)
b.isNeg = !b.isNeg,
c = biAdd(a, b),
b.isNeg = !b.isNeg;
else {
for (c = new BigInt,
e = 0,
f = 0; f < a.digits.length; ++f)
d = a.digits[f] - b.digits[f] + e,
c.digits[f] = 65535 & d,
c.digits[f] < 0 && (c.digits[f] += biRadix),
e = 0 - Number(0 > d);
if (-1 == e) {
for (e = 0,
f = 0; f < a.digits.length; ++f)
d = 0 - c.digits[f] + e,
c.digits[f] = 65535 & d,
c.digits[f] < 0 && (c.digits[f] += biRadix),
e = 0 - Number(0 > d);
c.isNeg = !a.isNeg
} else
c.isNeg = a.isNeg
}
return c
}
function biMultiplyDigit(a, b) {
var c, d, e, f;
for (result = new BigInt,
c = biHighIndex(a),
d = 0,
f = 0; c >= f; ++f)
e = result.digits[f] + a.digits[f] * b + d,
result.digits[f] = e & maxDigitVal,
d = e >>> biRadixBits;
return result.digits[1 + c] = d,
result
}
function biShiftRight(a, b) {
var e, f, g, h, c = Math.floor(b / bitsPerDigit), d = new BigInt;
for (arrayCopy(a.digits, c, d.digits, 0, a.digits.length - c),
e = b % bitsPerDigit,
f = bitsPerDigit - e,
g = 0,
h = g + 1; g < d.digits.length - 1; ++g,
++h)
d.digits[g] = d.digits[g] >>> e | (d.digits[h] & lowBitMasks[e]) << f;
return d.digits[d.digits.length - 1] >>>= e,
d.isNeg = a.isNeg,
d
}
function BarrettMu_modulo(a) {
var i, b = biDivideByRadixPower(a, this.k - 1), c = biMultiply(b, this.mu), d = biDivideByRadixPower(c, this.k + 1), e = biModuloByRadixPower(a, this.k + 1), f = biMultiply(d, this.modulus), g = biModuloByRadixPower(f, this.k + 1), h = biSubtract(e, g);
for (h.isNeg && (h = biAdd(h, this.bkplus1)),
i = biCompare(h, this.modulus) >= 0; i; )
h = biSubtract(h, this.modulus),
i = biCompare(h, this.modulus) >= 0;
return h
}
function BarrettMu_multiplyMod(a, b) {
var c = biMultiply(a, b);
return this.modulo(c)
}
function BarrettMu_powMod(a, b) {
var d, e, c = new BigInt;
for (c.digits[0] = 1,
d = a,
e = b; ; ) {
if (0 != (1 & e.digits[0]) && (c = this.multiplyMod(c, d)),
e = biShiftRight(e, 1),
0 == e.digits[0] && 0 == biHighIndex(e))
break;
d = this.multiplyMod(d, d)
}
return c
}
function encryptedString(a, b) {
for (var f, g, h, i, j, k, l, c = new Array, d = b.length, e = 0; d > e; )
c[e] = b.charCodeAt(e),
e++;
for (; 0 != c.length % a.chunkSize; )
c[e++] = 0;
for (f = c.length,
g = "",
e = 0; f > e; e += a.chunkSize) {
for (j = new BigInt,
h = 0,
i = e; i < e + a.chunkSize; ++h)
j.digits[h] = c[i++],
j.digits[h] += c[i++] << 8;
k = a.barrett.powMod(j, a.e),
l = 16 == a.radix ? biToHex(k) : biToString(k, a.radix),
g += l + " "
}
return g.substring(0, g.length - 1)
}
function biMultiply(a, b) {
var d, h, i, k, c = new BigInt, e = biHighIndex(a), f = biHighIndex(b);
for (k = 0; f >= k; ++k) {
for (d = 0,
i = k,
j = 0; e >= j; ++j,
++i)
h = c.digits[i] + a.digits[j] * b.digits[k] + d,
c.digits[i] = h & maxDigitVal,
d = h >>> biRadixBits;
c.digits[k + e + 1] = d
}
return c.isNeg = a.isNeg != b.isNeg,
c
}
function biDivideByRadixPower(a, b) {
var c = new BigInt;
return arrayCopy(a.digits, b, c.digits, 0, c.digits.length - b),
c
}
function biModuloByRadixPower(a, b) {
var c = new BigInt;
return arrayCopy(a.digits, 0, c.digits, 0, b),
c
}
function biToHex(a) {
var d, b = "";
for (biHighIndex(a),
d = biHighIndex(a); d > -1; --d)
b += digitToHex(a.digits[d]);
return b
}
function digitToHex(a) {
var b = 15
, c = "";
for (i = 0; 4 > i; ++i)
c += hexToChar[a & b],
a >>>= 4;
return reverseStr(c)
}
function reverseStr(a) {
var c, b = "";
for (c = a.length - 1; c > -1; --c)
b += a.charAt(c);
return b
}
function c(a, b, c) {
var d, e;
return setMaxDigits(131),
d = new RSAKeyPair(b,"",c),
e = encryptedString(d, a)
}
a = 'boBRdydPWcDp1S64'
b = '010001'
e = '00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7'
result = c(a,b,e)
console.log(result)
四、获取歌曲ID——以某个歌单为例
在类似https://music.163.com/playlist?id=7671136220
的请求返回的时HTML页面,使用bs4下的BeautifulSoup
可以分离出歌曲ID和歌曲名称!
下面是具体实现代码:
def get_href_title_list():
headers = {
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"accept-language": "zh-CN,zh;q=0.9",
"cookie": "NMTID=00ORLn9r4ajTG4-7UBNi_dVSUW9_LAAAAGNOSMGsw; _iuqxldmzr_=32; _ntes_nnid=9269216d9945dc4d6471881974b30083,1706060610074; _ntes_nuid=9269216d9945dc4d6471881974b30083; WEVNSM=1.0.0; WNMCID=wyncwu.1706060610383.01.0; WM_TID=Pem2675jFsZFVFAEFROV8grTGAtXEbl%2F; ntes_utid=tid._.V%252F1xGiqzNXxAQ0VEBROR9hvHHR4DUmih._.0; sDeviceId=YD-jZ%2BoGVSsthNAUlVBAEOApx7SWFpSBimn; __snaker__id=tbPyQTIdUChO2gBk; vinfo_n_f_l_n3=4b7277bf2755a2dc.1.1.1707831333313.1707831546398.1707971458165; MUSIC_U=007F97B2281C4FE9AF45316BF7483C5E24F54082032A8C934FE5793D5F606AE69768B7FD6CC0FDD4DB530BB223C2AE973EE135E7A57164CEB4B180E77839965BD7F28C456F11111552EE5EAFBC880181184C7845C2661F794AF3CF1C0287DE95EE281D212469057B3467215702204486D011BBDAE37FD78D72F86DE17B94A30480F33F050A8127E7782FE0BF1D79393604752ED11D6B3A954738FFF531FBD24CA90037787BE092A9D084D3A4A74BA4C6A3A54EB544489DAD9EE767ACB0AFEAC870F68CFD311068D450CFD5578D347C77F8E6FE7DF4C513FE286BBED8BA240C300187989E65827F6994D8D8AEE895C95033D8441D20B64EC6969ECB6DF22DEE92989DB60B4C006E14C25765B227825F90D09A704A0C99A226808124DBBDA08D2F7DB6616EFB425A8E49FD29EDBE23AA3DE597E81E6779397D05B777B1FA0A3A1F4B053822F1630652CA0EE7E7DA1306859453FCE9F8C67A2D50E37D2F6BBE242171; ntes_kaola_ad=1; __root_domain_v=.163.com; _qddaz=QD.476810123598468; wyy_uid=b74dd5f8-3ba7-49dc-a62c-0dc6c808c2ba; locale=zh_CN; __csrf=fcbba2252c7cd7ad57af5c140eaec00f; __csrf=fcbba2252c7cd7ad57af5c140eaec00f; JSESSIONID-WYYY=W7H3HEBuHKonQDo%2FeoRdP2Hbok727Gt5F2b%5CJe2QglgzbMBmIXHV7WTAha4eaKxcoBmonpbc510MnqpeqlQXXZpZ2JsudWCy5PFlGK1EVRqQw%2Bb4uieqeGheYPsDlIpvQlK3cHCI3YGcfDUBB%2FNmlf67AANCU8ZoUTptOOxgOJRGk6AA%3A1721638429253; WM_NI=vsp6EZ4tW22Rg%2FPMtAIHw5YHwpFvMC9va1BWhu8kUt6qw%2FqzQtNZ1AQHtH1U9V7rZa4SRWT6tEu2mdh9pYRuHBnM6UPu8JaJGlsQRB9k8%2FLnhx272Jib8fCufa1ODE32WTk%3D; WM_NIKE=9ca17ae2e6ffcda170e2e6eeafec63abeba5d0bb73a19e8fa7c54e878a8eacdb5fa2be8c8dd93c8df09aaee12af0fea7c3b92ab6adc0d7c852f8ac99d3b15aa5f1a0aef74b8b98b9d6dc44b5b08a97d049fbaaafd2c15dacabf88cd880f6afb9d0f47293ac82bbb44b9398bca9b45ffb8af993d96bf88d9eb8d73eb89bbbd3f070ace7c0bad17f8c9ea2aeb55f94abf8abe44285b4bdb2d14afbb5f8d0cf66aca8fed8b142abbef887c27fa6bfffb0c74ff1ee99b5ea37e2a3; playerid=84755767",
"priority": "u=0, i",
"referer": "https://music.163.com/",
"sec-ch-ua": "\\Chromium;v=\\124, \\Google",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\\Windows",
"sec-fetch-dest": "iframe",
"sec-fetch-mode": "navigate",
"sec-fetch-site": "same-origin",
"upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"
}
url = "https://music.163.com/playlist"
params = {
"id": "171037362"
}
response = requests.get(url, headers=headers, params=params)
soup = BeautifulSoup(response.text, 'lxml')
div = soup.find('div', id='song-list-pre-cache')
ul = div.find('ul')
lis = ul.find_all('li')
songs = []
for li in lis:
a = li.find('a')
href = a['href']
title = a.text
songs.append({
'ids': href.split('=')[1],
'title': title
})
return songs
然后就是将ID传入JS文件得到请求参数,发送请求得到m4a的音频地址,再用该地址进行请求,将返回结果的content写入文件,至此歌曲就下载完成了。后续还会更新更多平台喔!
标签:digits,Web,return,function,params,isNeg,var,new,encSecKey From: https://blog.csdn.net/Poboll/article/details/142711143