(JSON.stringify(i6c), bsK7D(["流泪", "强"]), bsK7D(XR0x.md), bsK7D(["爱心", "女孩", "惊恐", "大笑"])
i6c: {
key: "1b601cd2-960c-4ee5-b1c6-e90dcc5a3f59", type: "1", csrf_token: ""}
Return value: "010001"
Return value: "00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7"
Return value: "0CoJUm6Qyw8W8jud"
- i6c: {key: “1b601cd2-960c-4ee5-b1c6-e90dcc5a3f59”, type: “1”, csrf_token: “”}
- Return value: "010001"
- Return value: "00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7"
- Return value:"0CoJUm6Qyw8W8jud"
function S() {
var e = (new Date).getTime();
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(t) {
var n = (e + 16 * Math.random()) % 16 | 0;
return e = Math.floor(e / 16),
("x" === t ? n : 7 & n | 8).toString(16)
})
}
-上面四个参数获取到了,还有一个大包围window.asrsea
var bWv7o = window.asrsea(JSON.stringify(i6c), bsK7D(["流泪", "强"]), bsK7D(XR0x.md), bsK7D(["爱心", "女孩", "惊恐", "大笑"]));
d: "{"key":"1b601cd2-960c-4ee5-b1c6-e90dcc5a3f59","type":"1","csrf_token":""}"
e: "010001"
f: "00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7"
g: "0CoJUm6Qyw8W8jud"
进一步化简:
i = a(16)
h.encText = b(d, g)
h.encText = b(h.encText, i)
h.encSecKey = c(i, e, f)
大概就这个意思
encText = b(b(d, g), i)
encSecKey = c(i, e, f)
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
}
可以看出这就是由这段代码随机生成的16位值
iv:0102030405060708
d: "{"key":"1b601cd2-960c-4ee5-b1c6-e90dcc5a3f59","type":"1","csrf_token":""}"
g: "0CoJUm6Qyw8W8jud"
def keys(key):
while len(key) % 16 != 0:
key += '\0'
return str.encode(key)
#AES解密
def AES_aes(t, key, iv):
p = lambda s: s + (AES.block_size - len(s) % AES.block_size) * chr(AES.block_size - len(s) % AES.block_size)
encrypt = str(base64.encodebytes(AES.new(keys(key), AES.MODE_CBC,keys(iv)).encrypt(str.encode(p(t)))), encoding='utf-8')
return encrypt
#将上面参数d, g, iv带入其中就行
def params(): #b(b(d, g), i)和下面是不是很相似
return AES_aes(AES_aes(d, g, iv), i, iv) #g 和 i 都是key代替
def RSA_rsa(i, e, f):
return format(int(codecs.encode(i[::-1].encode('utf-8'), 'hex_codec'), 16) ** int(e, 16) % int(f, 16), 'x').zfill(256)
def encSecKey():
return RSA_rsa(i, e, f)
def params():
return AES_aes(AES_aes(d, g, iv), i, iv)
def encSecKey():
return RSA_rsa(i, e, f)
解决方法:
安装crypto后,将\venv\Lib\site-packages\crypto的crypto文件夹名首字母c改成大写C就可以了
#访问生成二维码网址的d值是这样的,其他不变,下面的确认网址的d值有所不一样
#key上面已经说了,这里的key值是随机生成的
d = str({
'key': key, 'type': "1", 'csrf_token': ""})
def params():
return AES_aes(AES_aes(d, g, iv), i, iv)
def encSecKey():
return RSA_rsa(i, e, f)
getlogin = session.post('https://music.163.com/weapi/login/qrcode/unikey?csrf_token=', data={
'params': params(), 'encSecKey': encSecKey()}, headers=headers).json()
#输出getlogin = {'code': 200, 'unikey': '3d99……'}
https://music.163.com/login?codekey=52f86249-fa48-4914-a324-0df788108e05&refer=scan
pngurl = 'https://music.163.com/login?codekey='+getlogin['unikey']+'&refer=scan'
qr = qrcode.QRCode()
qr.add_data(pngurl)
img = qr.make_image()
# 缓存的好处就是不需要保存本地
a = BytesIO()
img.save(a, 'png')
png = a.getvalue()
a.close()
# 打开二维码进行扫码操作
t = showpng(png)
t.start()
tokenurl = 'https://music.163.com/weapi/login/qrcode/client/login?csrf_token='
while 1:
u = str({
'key': getlogin['unikey'], 'type': "1", 'csrf_token': ""})
qrcodedata = session.post(tokenurl, data={
'params': AES_aes(AES_aes(u, g, iv), i, iv), 'encSecKey': encSecKey()}, headers=headers).json()
if '801' in str(qrcodedata['code']):
print('二维码未失效,请扫码!')
elif '802' in str(qrcodedata['code']):
print('已扫码,请确认!')
elif '803' in str(qrcodedata['data']['code']):
print('已确认,登入成功!')
break
else:
print('其他:', qrcodedata)
time.sleep(2)
csrf_token=53b3e139d912……
def islogin(session):
try:
session.cookies.load(ignore_discard=True)
except Exception:
pass
#从cookie提取csrf_token值
csrf_token = session.cookies.get('__csrf')
c = str({
'csrf_token': csrf_token})
try:
loginurl = session.post('https://music.163.com/weapi/w/nuser/account/get?csrf_token={}'.format(csrf_token), data={
'params': AES_aes(AES_aes(c, g, iv), i, iv), 'encSecKey': encSecKey()}, headers=headers).json()
if '200' in str(loginurl['code']):
print('Cookies值有效:',loginurl['profile']['nickname'],',已登录!')
return session, True
else:
print('Cookies值已经失效,请重新扫码登录!')
return session, False
except:
print('Cookies值已经失效,请重新扫码登录!')
return session, False
# -*- coding: UTF-8 -*-
import random
import random
import execjs
agent = [
"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36",
#可以多添加几个
]
# 获取浏览器认证头
def get_user_agents():
return random.choice(agent)
# 读取js
def djs(js):
f = open(js, 'r', encoding='utf-8')
jst = ''
while True:
readline = f.readline()
if readline:
jst += readline
else:
break
return jst
def getjs():
return djs('jsdm.js')
# 获取ptqrtoken
def ptqrtoken(qrsign):
# 加载js
execjs_execjs = execjs.compile(getjs())
return execjs_execjs.call('hash33', qrsign)
# 获取UI
def guid():
# 加载js
execjs_execjs = execjs.compile(getjs())
return execjs_execjs.call('guid')
# 获取g_tk
def get_g_tk(p_skey):
# 加载js
execjs_execjs = execjs.compile(getjs())
return execjs_execjs.call('getToken', p_skey)
# 获取i
def S():
# 加载js
execjs_execjs = execjs.compile(getjs())
return execjs_execjs.call('S')
# 获取key
def a():
# 加载js
execjs_execjs = execjs.compile(getjs())
return execjs_execjs.call('a', 16)
function hash33(t) {
for (var e = 0, i = 0, n = t.length; i < n; ++i)
e += (e << 5) + t.charCodeAt(i);
return 2147483647 & e
}
function getToken(p_skey) {
var str = p_skey || '',
hash = 5381;
for (var i = 0, len = str.length; i < len; ++i) {
hash += (hash << 5) + str.charCodeAt(i);
}
return hash & 0x7fffffff;
}
function guid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
}).toUpperCase();
};
function S() {
var e = (new Date).getTime();
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(t) {
var n = (e + 16 * Math.random()) % 16 | 0;
return e = Math.floor(e / 16),
("x" === t ? n : 7 & n | 8).toString(16)
})
}
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
}
# -*- coding: utf-8 -*-
import base64
import codecs
import pickle
from Crypto.Cipher import AES
#解决方法:安装crypto后,将\venv\Lib\site-packages\crypto的crypto文件夹名首字母c改成大写C就可以了
import qrcode
import agent
from threading import Thread
import time
import requests
from io import BytesIO
from PIL import Image
import os
requests.packages.urllib3.disable_warnings()
headers = {
'User-Agent': agent.get_user_agents(),'Referer':'https://music.163.com/'}
class showpng(Thread):
def __init__(self, data):
Thread.__init__(self)
self.data = data
def run(self):
img = Image.open(BytesIO(self.data))
img.show()
#解密params和encSecKey值
def keys(key):
while len(key) % 16 != 0:
key += '\0'
return str.encode(key)
def AES_aes(t, key, iv):
p = lambda s: s + (AES.block_size - len(s) % AES.block_size) * chr(AES.block_size - len(s) % AES.block_size)
encrypt = str(base64.encodebytes(AES.new(keys(key), AES.MODE_CBC,keys(iv)).encrypt(str.encode(p(t)))), encoding='utf-8')
return encrypt
def RSA_rsa(i, e, f):
return format(int(codecs.encode(i[::-1].encode('utf-8'), 'hex_codec'), 16) ** int(e, 16) % int(f, 16), 'x').zfill(256)
#获取的参数
key = agent.S() # i6c的值
d = str({
'key': key, 'type': "1", 'csrf_token': ""})
e = "010001"# (["流泪", "强"])的值
f = "00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7"
g = "0CoJUm6Qyw8W8jud" # (["爱心", "女孩", "惊恐", "大笑"])的值
iv = "0102030405060708" # 偏移量
i = agent.a() # 随机生成长度为16的字符串
def params():
return AES_aes(AES_aes(d, g, iv), i, iv) #g 和 i 都是key代替
def encSecKey():
return RSA_rsa(i, e, f)
#判断cookie是否有效
def islogin(session):
try:
session.cookies.load(ignore_discard=True)
except Exception:
pass
csrf_token = session.cookies.get('__csrf')
c = str({
'csrf_token': csrf_token})
try:
loginurl = session.post('https://music.163.com/weapi/w/nuser/account/get?csrf_token={}'.format(csrf_token), data={
'params': AES_aes(AES_aes(c, g, iv), i, iv), 'encSecKey': encSecKey()}, headers=headers).json()
if '200' in str(loginurl['code']):
print('Cookies值有效:',loginurl['profile']['nickname'],',已登录!')
return session, True
else:
print('Cookies值已经失效,请重新扫码登录!')
return session, False
except:
print('Cookies值已经失效,请重新扫码登录!')
return session, False
#登录扫码保存cookie
def wyylogin():
# 写入
session = requests.session()
if not os.path.exists('wyycookies.cookie'):
with open('wyycookies.cookie', 'wb') as f:
pickle.dump(session.cookies, f)
# 读取
session.cookies = pickle.load(open('wyycookies.cookie', 'rb'))
session, status = islogin(session)
if not status:
getlogin = session.post('https://music.163.com/weapi/login/qrcode/unikey?csrf_token=', data={
'params': params(), 'encSecKey': encSecKey()}, headers=headers).json()
pngurl = 'https://music.163.com/login?codekey=' + getlogin['unikey'] + '&refer=scan'
qr = qrcode.QRCode()
qr.add_data(pngurl)
img = qr.make_image()
# 缓存的好处就是不需要保存本地
a = BytesIO()
img.save(a, 'png')
png = a.getvalue()
a.close()
# 打开二维码进行扫码操作
t = showpng(png)
t.start()
tokenurl = 'https://music.163.com/weapi/login/qrcode/client/login?csrf_token='
while 1:
u = str({
'key': getlogin['unikey'], 'type': "1", 'csrf_token': ""})
qrcodedata = session.post(tokenurl, data={
'params': AES_aes(AES_aes(u, g, iv), i, iv), 'encSecKey': encSecKey()}, headers=headers).json()
if '801' in str(qrcodedata['code']):
print('二维码未失效,请扫码!')
elif '802' in str(qrcodedata['code']):
print('已扫码,请确认!')
elif '803' in str(qrcodedata['code']):
print('已确认,登入成功!')
break
else:
print('其他:', qrcodedata)
time.sleep(2)
with open('wyycookies.cookie', 'wb') as f:
pickle.dump(session.cookies, f)
return session
if __name__ == '__main__':
wyylogin()
- 后期小编将开设登录后批量采集各平台数据(点赞、播放量、评论、图片、视频、音乐等)专栏文章!记得关注哟!
- 如果文章能帮到您,愿意给小编点个 赞 吗,么么哒~ (●’◡’●)