perf: 优化提取链接的正则表达式

Closes #261
This commit is contained in:
Quan 2025-07-28 17:30:53 +08:00
parent b63f546b3a
commit e0fbd7916d
2 changed files with 9 additions and 4 deletions

View File

@ -74,11 +74,12 @@ class XHS:
VERSION_MAJOR = VERSION_MAJOR
VERSION_MINOR = VERSION_MINOR
VERSION_BETA = VERSION_BETA
LINK = compile(r"https?://www\.xiaohongshu\.com/explore/\S+")
USER = compile(r"https?://www\.xiaohongshu\.com/user/profile/[a-z0-9]+/\S+")
SHARE = compile(r"https?://www\.xiaohongshu\.com/discovery/item/\S+")
SHORT = compile(r"https?://xhslink\.com/[^\s\"<>\\^`{|},。;!?、【】《》]+")
LINK = compile(r"(?:https?://)?www\.xiaohongshu\.com/explore/\S+")
USER = compile(r"(?:https?://)?www\.xiaohongshu\.com/user/profile/[a-z0-9]+/\S+")
SHARE = compile(r"(?:https?://)?www\.xiaohongshu\.com/discovery/item/\S+")
SHORT = compile(r"(?:https?://)?xhslink\.com/[^\s\"<>\\^`{|},。;!?、【】《》]+")
ID = compile(r"(?:explore|item)/(\S+)?\?")
ID_USER = compile(r"user/profile/[a-z0-9]+/(\S+)?\?")
__INSTANCE = None
CLEANER = Cleaner()
@ -286,6 +287,8 @@ class XHS:
for i in links:
if j := self.ID.search(i):
ids.append(j.group(1))
elif j := self.ID_USER.search(i):
ids.append(j.group(1))
return ids
async def __deal_extract(

View File

@ -32,6 +32,8 @@ class Html:
proxy: str = None,
**kwargs,
) -> str:
if not url.startswith("http"):
url = f"https://{url}"
headers = self.update_cookie(
cookie,
)