043-spiderbuf第C3题

案例网址:spiderbuf第C3题

找接口+找加密参数

网页有翻页,可以翻页找xhr接口:

py通过注释或删除验证需要逆向的参数:

就hash是密文,但是前三个又不得不带,那很有可能hash是由前三个加密生成的

找加密位置

启动器进入:

很简单,应该是标准md5,可以验证看看:

ok,标准md5

复现加密逻辑

看一下其他参数怎么来的:

一个是随机数×1000,一个是时间戳,一个是和时间戳做^运算(逐位异或),下面开始编写代码:

javascript 复制代码
const CryptoJS = require('crypto-js');
function md5(decData) {
  return CryptoJS.MD5(decData).toString();
}
function getParams(_0x3d0eeb) {
  const _0x1fa068 = Math["floor"](Math["random"]() * (8000) + (2000));
  const _0x542b78 = Math['floor'](Date["now"]() / (1000));
  const _0x39669e = _0x3d0eeb ^ _0x542b78;
  const _0x56e6b4 = md5('' + _0x39669e + _0x542b78)['toString']();
  let params = {
    xorResult: _0x39669e,
    random: _0x1fa068,
    timestamp: _0x542b78,
    hash: _0x56e6b4
  };
  return JSON.stringify(params);
}

console.log(getParams(1));

py调用

python 复制代码
import requests
import execjs
import os
class JSExecutor:
    def __init__(self, js_file_path):
        if not os.path.exists(js_file_path):
            print(f'js代码不存在:{js_file_path}')

        with open(js_file_path, 'r', encoding='utf-8') as f:
            self.js_code = f.read()

        # execjs.compile() 将JavaScript 代码编译为一个可执行的对象
        self.js_code = execjs.compile(self.js_code)

    def call(self, func_name, *args):
        """
        封装python对js代码中函数的调用
        :param func_name: js代码中的函数名
        :param args: js代码中函数所需的参数
        :return: js中函数运行后的结果
        """
        return self.js_code.call(func_name, *args)
def get_data(js_data):
    headers = {
        'origin': 'https://www.spiderbuf.cn',
        'referer': 'https://www.spiderbuf.cn/web-scraping-practice/scraper-practice-c03',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36 Edg/145.0.0.0',
    }

    data = js_data

    response = requests.post(
        'https://www.spiderbuf.cn/web-scraping-practice/scraper-practice-c03',
        headers=headers,
        data=data,
    )
    return response.json()

def get_params(page):
    js_executor = JSExecutor('xxx.js')
    js_data = js_executor.call('getParams', page)
    return get_data(js_data)

def main():
    for page in range(1, 4):
        print(f'-----------正在爬取第{page}页--------------')
        params = get_params(page)
        print(params)

if __name__ == '__main__':
    main()

result:

拿下

小结

本文依旧简单,spiderbuf就做到这里吧,如有问题请及时提出,加油加油

相关推荐
Csvn1 天前
🌟 LangChain 30 天保姆级教程 · Day 13|OutputParser 进阶!让 AI 输出自动转为结构化对象,并支持自动重试!
python·langchain
cch89181 天前
Python主流框架全解析
开发语言·python
sg_knight1 天前
设计模式实战:状态模式(State)
python·ui·设计模式·状态模式·state
好运的阿财1 天前
process 工具与子agent管理机制详解
网络·人工智能·python·程序人生·ai编程
张張4081 天前
(域格)环境搭建和编译
c语言·开发语言·python·ai
weixin_423533991 天前
【Windows11离线安装anaconda、python、vscode】
开发语言·vscode·python
Ricky111zzz1 天前
leetcode学python记录1
python·算法·leetcode·职场和发展
小白学大数据1 天前
Selenium+Python 爬虫:动态加载头条问答爬取
爬虫·python·selenium
Hui Baby1 天前
springboot读取配置文件
后端·python·flask
阿Y加油吧1 天前
回溯法经典难题:N 皇后问题 深度解析 + 二分查找入门(搜索插入位置)
开发语言·python