From 89d9ff2cd63e8eb8a241ea14c06c818083523f3c Mon Sep 17 00:00:00 2001 From: fllesser Date: Wed, 7 Jan 2026 12:59:56 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(config):=20=E6=B7=BB=E5=8A=A0=20`parse?= =?UTF-8?q?r=5Fxhs=5Fck`=20=EF=BC=8C=E7=94=A8=E4=BA=8E=20explore=20?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E6=97=A0=E6=B0=B4=E5=8D=B0=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +++ src/nonebot_plugin_parser/config.py | 7 +++++++ src/nonebot_plugin_parser/parsers/xiaohongshu/__init__.py | 7 ++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1cf1b3aa..cd9c0f42 100644 --- a/README.md +++ b/README.md @@ -209,6 +209,9 @@ parser_bili_video_codes='["avc", "av01", "hev"]' # 360p(16), 480p(32), 720p(64), 1080p(80), 1080p+(112), 1080p_60(116), 4k(120) parser_bili_video_quality=80 +# [可选] 小红书 Cookie, 部分链接解析有水印,可填 +parser_xhs_ck="" + # [可选] Youtube Cookie, Youtube 视频因人机检测下载失败,需填 parser_ytb_ck="" diff --git a/src/nonebot_plugin_parser/config.py b/src/nonebot_plugin_parser/config.py index 76b47d5f..4d9f75cf 100644 --- a/src/nonebot_plugin_parser/config.py +++ b/src/nonebot_plugin_parser/config.py @@ -20,6 +20,8 @@ class Config(BaseModel): """bilibili cookies""" parser_ytb_ck: str | None = None """youtube cookies""" + parser_xhs_ck: str | None = None + """小红书 cookies""" parser_proxy: str | None = None """代理""" parser_need_upload: bool = False @@ -113,6 +115,11 @@ def ytb_ck(self) -> str | None: """youtube cookies""" return self.parser_ytb_ck + @property + def xhs_ck(self) -> str | None: + """小红书 cookies""" + return self.parser_xhs_ck + @property def proxy(self) -> str | None: """代理""" diff --git a/src/nonebot_plugin_parser/parsers/xiaohongshu/__init__.py b/src/nonebot_plugin_parser/parsers/xiaohongshu/__init__.py index 1b920891..c946ec08 100644 --- a/src/nonebot_plugin_parser/parsers/xiaohongshu/__init__.py +++ b/src/nonebot_plugin_parser/parsers/xiaohongshu/__init__.py @@ -4,7 +4,7 @@ from httpx import Cookies, AsyncClient from nonebot import logger -from ..base import Platform, BaseParser, PlatformEnum, ParseException, handle +from ..base import Platform, BaseParser, PlatformEnum, ParseException, handle, pconfig from ..data import MediaContent @@ -21,6 +21,7 @@ def __init__(self): ) } self.headers.update(explore_headers) + discovery_headers = { "origin": "https://www.xiaohongshu.com", "x-requested-with": "XMLHttpRequest", @@ -30,6 +31,10 @@ def __init__(self): } self.ios_headers.update(discovery_headers) + if pconfig.parser_xhs_ck: + self.headers["cookie"] = pconfig.parser_xhs_ck + self.ios_headers["cookie"] = pconfig.parser_xhs_ck + @handle("xhslink.com", r"xhslink\.com/[A-Za-z0-9._?%&+=/#@-]+") async def _parse_short_link(self, searched: re.Match[str]): url = f"https://{searched.group(0)}" From ee2f6fdfde69562b75ef4a8a99428c9dedf21be0 Mon Sep 17 00:00:00 2001 From: fllesser Date: Wed, 7 Jan 2026 13:01:00 +0800 Subject: [PATCH 2/2] tweak --- src/nonebot_plugin_parser/parsers/xiaohongshu/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nonebot_plugin_parser/parsers/xiaohongshu/__init__.py b/src/nonebot_plugin_parser/parsers/xiaohongshu/__init__.py index c946ec08..6961e874 100644 --- a/src/nonebot_plugin_parser/parsers/xiaohongshu/__init__.py +++ b/src/nonebot_plugin_parser/parsers/xiaohongshu/__init__.py @@ -31,9 +31,9 @@ def __init__(self): } self.ios_headers.update(discovery_headers) - if pconfig.parser_xhs_ck: - self.headers["cookie"] = pconfig.parser_xhs_ck - self.ios_headers["cookie"] = pconfig.parser_xhs_ck + if pconfig.xhs_ck: + self.headers["cookie"] = pconfig.xhs_ck + self.ios_headers["cookie"] = pconfig.xhs_ck @handle("xhslink.com", r"xhslink\.com/[A-Za-z0-9._?%&+=/#@-]+") async def _parse_short_link(self, searched: re.Match[str]):