diff --git a/service/douyin/logic/common.py b/service/douyin/logic/common.py index 87ad8df..21f5587 100644 --- a/service/douyin/logic/common.py +++ b/service/douyin/logic/common.py @@ -57,7 +57,7 @@ "dnt": "1", } -DOUYIN_SIGN = execjs.compile(open('lib/js/douyin.js').read()) +DOUYIN_SIGN = execjs.compile(open('lib/js/douyin.js', encoding='utf-8').read()) async def get_webid(headers: dict): url = 'https://www.douyin.com/?recommend=1' diff --git a/service/xhs/logic/common.py b/service/xhs/logic/common.py index 6ed4865..0b71569 100644 --- a/service/xhs/logic/common.py +++ b/service/xhs/logic/common.py @@ -39,7 +39,7 @@ async def common_request(uri: str, params: dict, headers: dict, need_sign: bool if post: if need_sign: - xhs_sign_obj = execjs.compile(open('lib/js/xhs.js').read()) + xhs_sign_obj = execjs.compile(open('lib/js/xhs.js', encoding='utf-8').read()) sign_header = xhs_sign_obj.call('sign', uri, params, headers.get('cookie', '')) headers.update(sign_header) @@ -54,7 +54,7 @@ async def common_request(uri: str, params: dict, headers: dict, need_sign: bool url = f'{url}?{params_str}' if need_sign: - xhs_sign_obj = execjs.compile(open('lib/js/xhs.js').read()) + xhs_sign_obj = execjs.compile(open('lib/js/xhs.js', encoding='utf-8').read()) sign_header = xhs_sign_obj.call('sign', uri, None, headers.get('cookie', '')) headers.update(sign_header) diff --git a/service/xhs/logic/search.py b/service/xhs/logic/search.py index 7ab4f69..102413b 100644 --- a/service/xhs/logic/search.py +++ b/service/xhs/logic/search.py @@ -9,7 +9,7 @@ async def request_search(keyword: str, cookie: str, offset: int = 0, limit: int page_size = 20 start_page = int( offset / page_size ) + 1 end_page = int((offset + limit - 1) / page_size) + 1 - xhs_sign_obj = execjs.compile(open('lib/js/xhs.js').read()) + xhs_sign_obj = execjs.compile(open('lib/js/xhs.js', encoding='utf-8').read()) tasks = [request_page(page, keyword, cookie, page_size, xhs_sign_obj) for page in range(start_page, end_page + 1)] pages = await asyncio.gather(*tasks) results = []