From bbaf20cf8fbb3d72ee50e7e7f7ccd02fc3866711 Mon Sep 17 00:00:00 2001 From: Evil0ctal Date: Fri, 14 Jun 2024 00:59:41 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8:=20Add=20Douyin=20Web=20A=5FBogus?= =?UTF-8?q?=20encryption=20algorithm=20Support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crawlers/douyin/web/utils.py | 46 ++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/crawlers/douyin/web/utils.py b/crawlers/douyin/web/utils.py index 40a0a09..9875746 100644 --- a/crawlers/douyin/web/utils.py +++ b/crawlers/douyin/web/utils.py @@ -42,7 +42,7 @@ from pathlib import Path from typing import Union from urllib.parse import urlencode, quote -import execjs +# import execjs import httpx import qrcode import yaml @@ -267,28 +267,28 @@ class BogusManager: # 字符串方法生成A-Bogus参数 # TODO: 未完成测试,暂时不提交至主分支。 - @classmethod - def ab_str_2_endpoint_js_ver(cls, endpoint: str, user_agent: str) -> str: - try: - # 获取请求参数 - endpoint_query_params = urllib.parse.urlparse(endpoint).query - # 确定A-Bogus JS文件路径 - js_path = os.path.dirname(os.path.abspath(__file__)) - a_bogus_js_path = os.path.join(js_path, 'a_bogus.js') - with open(a_bogus_js_path, 'r', encoding='utf-8') as file: - js_code = file.read() - # 此处需要使用Node环境 - # - 安装Node.js - # - 安装execjs库 - # - 安装NPM依赖 - # - npm install jsdom - node_runtime = execjs.get('Node') - context = node_runtime.compile(js_code) - arg = [0, 1, 0, endpoint_query_params, "", user_agent] - a_bougus = quote(context.call('get_a_bogus', arg), safe='') - return a_bougus - except Exception as e: - raise RuntimeError("生成A-Bogus失败: {0})".format(e)) + # @classmethod + # def ab_str_2_endpoint_js_ver(cls, endpoint: str, user_agent: str) -> str: + # try: + # # 获取请求参数 + # endpoint_query_params = urllib.parse.urlparse(endpoint).query + # # 确定A-Bogus JS文件路径 + # js_path = os.path.dirname(os.path.abspath(__file__)) + # a_bogus_js_path = os.path.join(js_path, 'a_bogus.js') + # with open(a_bogus_js_path, 'r', encoding='utf-8') as file: + # js_code = file.read() + # # 此处需要使用Node环境 + # # - 安装Node.js + # # - 安装execjs库 + # # - 安装NPM依赖 + # # - npm install jsdom + # node_runtime = execjs.get('Node') + # context = node_runtime.compile(js_code) + # arg = [0, 1, 0, endpoint_query_params, "", user_agent] + # a_bougus = quote(context.call('get_a_bogus', arg), safe='') + # return a_bougus + # except Exception as e: + # raise RuntimeError("生成A-Bogus失败: {0})".format(e)) # 字典方法生成A-Bogus参数,感谢 @JoeanAmier 提供的纯Python版本算法。 @classmethod