"""小红书 URL 常量和构建函数。""" from urllib.parse import urlencode # 基础页面 EXPLORE_URL = "https://www.xiaohongshu.com/explore" HOME_URL = "https://www.xiaohongshu.com" PUBLISH_URL = "https://creator.xiaohongshu.com/publish/publish?source=official" def make_feed_detail_url(feed_id: str, xsec_token: str = "") -> str: """构建 feed 详情页 URL。xsec_token 为列表/详情接口返回的访问凭证,浏览器打开笔记页时仍需要。""" base = f"https://www.xiaohongshu.com/explore/{feed_id}" token = (xsec_token or "").strip() if not token: return base return f"{base}?xsec_token={token}&xsec_source=pc_feed" def make_search_url(keyword: str) -> str: """构建搜索结果页 URL(与小红书搜索页当前 source 参数一致)。""" params = urlencode({"keyword": keyword, "source": "web_search_result_notes"}) return f"https://www.xiaohongshu.com/search_result?{params}" def make_user_profile_url(user_id: str, xsec_token: str = "") -> str: """构建用户主页 URL。""" base = f"https://www.xiaohongshu.com/user/profile/{user_id}" token = (xsec_token or "").strip() if not token: return base return f"{base}?xsec_token={token}&xsec_source=pc_note"