喜馬拉雅節目爬取

生而自由爱而无畏發表於2024-04-14
1. python部分:

喜馬拉雅.py

# -*- coding:utf-8 -*-

# @Time : 2024/4/14 9:47
# @Author : 快樂的小猴子
# @Version :
# @Function : 爬取喜馬拉雅節目資料
import requests
import subprocess
from functools import partial   # 專門用來固定引數的
subprocess.Popen = partial(subprocess.Popen, encoding = "utf-8")
import execjs
with open('喜馬拉雅.js', 'r', encoding='utf-8') as f:
    json_data = f.read()

context = execjs.compile(json_data)
res = context.call('main')

url = 'https://www.ximalaya.com/revision/metadata/v2/channel/albums'
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36",
    "Referer": "https://www.ximalaya.com/channel/p2/",
    "Xm-Sign": res
}
# print(headers)
# exit()
params = {
    "pageNum": 3,
    "pageSize": 50,
    "sort": 1,
    "metadata": "",
}
resp = requests.get(url, headers=headers, params=params)
print(resp.json())
2. JavaScript部分:

喜馬拉雅.js

var u = function(t) {
    return ~~(Math['random']() * t)
}

let crypto = require('crypto');
function do_md5(e) {
    return crypto.createHash('md5').update(e.toString()).digest('hex');
}

function main() {
    var t, e, r, n = 0;
    // return n = false ? Date.now() : window.XM_SERVER_CLOCK || 0,
    return n = Date.now(),
    t = this['himalaya-'],
    e = n,
    r = Date['now'](),
    ("{" + t + e + "}(" + u(100) + ")" + e + "(" + u(100) + ")" + r)['replace'](/{([\w-]+)}/, (function(t, e) {
        return do_md5(e)
    }
    ))
};

console.log(main());

執行資料結果截圖:
image

相關文章