mirror of
https://github.com/NanmiCoder/MediaCrawler.git
synced 2026-06-09 03:17:25 +08:00
feat: update douyin abogus params
This commit is contained in:
@@ -34,7 +34,7 @@ class DOUYINClient(AbstractApiClient):
|
||||
self.cookie_dict = cookie_dict
|
||||
|
||||
async def __process_req_params(
|
||||
self, params: Optional[Dict] = None, headers: Optional[Dict] = None,
|
||||
self, uri: str, params: Optional[Dict] = None, headers: Optional[Dict] = None,
|
||||
request_method="GET"
|
||||
):
|
||||
|
||||
@@ -73,11 +73,11 @@ class DOUYINClient(AbstractApiClient):
|
||||
params.update(common_params)
|
||||
query_string = urllib.parse.urlencode(params)
|
||||
|
||||
# 20240610 a-bogus更新(Playwright版本)
|
||||
# 20240927 a-bogus更新(JS版本)
|
||||
post_data = {}
|
||||
if request_method == "POST":
|
||||
post_data = params
|
||||
a_bogus = await get_a_bogus(query_string, post_data, headers["User-Agent"], self.playwright_page)
|
||||
a_bogus = await get_a_bogus(uri, query_string, post_data, headers["User-Agent"], self.playwright_page)
|
||||
params["a_bogus"] = a_bogus
|
||||
|
||||
async def request(self, method, url, **kwargs):
|
||||
@@ -98,12 +98,12 @@ class DOUYINClient(AbstractApiClient):
|
||||
"""
|
||||
GET请求
|
||||
"""
|
||||
await self.__process_req_params(params, headers)
|
||||
await self.__process_req_params(uri, params, headers)
|
||||
headers = headers or self.headers
|
||||
return await self.request(method="GET", url=f"{self._host}{uri}", params=params, headers=headers)
|
||||
|
||||
async def post(self, uri: str, data: dict, headers: Optional[Dict] = None):
|
||||
await self.__process_req_params(data, headers)
|
||||
await self.__process_req_params(uri, data, headers)
|
||||
headers = headers or self.headers
|
||||
return await self.request(method="POST", url=f"{self._host}{uri}", data=data, headers=headers)
|
||||
|
||||
|
||||
@@ -6,8 +6,10 @@
|
||||
|
||||
import random
|
||||
|
||||
import execjs
|
||||
from playwright.async_api import Page
|
||||
|
||||
douyin_sign_obj = execjs.compile(open('libs/douyin.js', encoding='utf-8').read())
|
||||
|
||||
def get_web_id():
|
||||
"""
|
||||
@@ -30,16 +32,35 @@ def get_web_id():
|
||||
return web_id.replace('-', '')[:19]
|
||||
|
||||
|
||||
async def get_a_bogus(params: str, post_data: dict, user_agent: str, page: Page = None):
|
||||
|
||||
async def get_a_bogus(url: str, params: str, post_data: dict, user_agent: str, page: Page = None):
|
||||
"""
|
||||
获取 a_bogus 参数
|
||||
获取 a_bogus 参数, 目前不支持post请求类型的签名
|
||||
"""
|
||||
return await get_a_bogus_from_playright(params, post_data, user_agent, page)
|
||||
return get_a_bogus_from_js(url, params, user_agent)
|
||||
|
||||
def get_a_bogus_from_js(url: str, params: str, user_agent: str):
|
||||
"""
|
||||
通过js获取 a_bogus 参数
|
||||
Args:
|
||||
url:
|
||||
params:
|
||||
user_agent:
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
sign_js_name = "sign_datail"
|
||||
if "/reply" in url:
|
||||
sign_js_name = "sign_reply"
|
||||
return douyin_sign_obj.call(sign_js_name, params, user_agent)
|
||||
|
||||
|
||||
|
||||
async def get_a_bogus_from_playright(params: str, post_data: dict, user_agent: str, page: Page):
|
||||
"""
|
||||
通过playright获取 a_bogus 参数
|
||||
playwright版本已失效
|
||||
Returns:
|
||||
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user