from xhshow import Xhshow
import requests
client = Xhshow()
# GET请求签名
signature = client.sign_xs_get(
uri="https://edith.xiaohongshu.com/api/sns/web/v1/user_posted", # v0.1.3及后续版本支持自动提取uri
# uri="/api/sns/web/v1/user_posted" # v0.1.2及以前版本需要主动提取uri
a1_value="your_a1_cookie_value",
params={"num": "30", "cursor": "", "user_id": "123"}
)
# POST请求签名
signature = client.sign_xs_post(
uri="https://edith.xiaohongshu.com/api/sns/web/v1/login",
a1_value="your_a1_cookie_value",
payload={"username": "test", "password": "123456"}
)
# 构建符合xhs平台的GET请求链接
full_url = client.build_url(
base_url="https://edith.xiaohongshu.com/api/sns/web/v1/user_posted",
params={"num": "30", "cursor": "", "user_id": "123"}
)
response = requests.get(full_url, headers=headers, cookies=cookies)
# 构建符合xhs平台的POST请求body
json_body = client.build_json_body(
payload={"username": "test", "password": "123456"}
)
response = requests.post(url, data=json_body, headers=headers, cookies=cookies)
# 解密 x3 签名
decoded_bytes = client.decode_x3("mns0101_Q2vPHtH+lQJYGQfhxG271BIvFFhx...")
# 解密完整的 XYS 签名
decoded_data = client.decode_xs("XYS_2UQhPsHCH0c1Pjh9HjIj2erjwjQhyoPT...")
from xhshow import CryptoConfig
from dataclasses import replace
custom_config = replace(
CryptoConfig(),
X3_PREFIX="custom_",
SIGNATURE_DATA_TEMPLATE={"x0": "4.2.6", "x1": "xhs-pc-web", ...}
)
client = Xhshow(config=custom_config)
uri: 请求URI(去除https域名和查询参数)
a1_value: cookie中的a1值
xsec_appid: 应用标识符,默认为 xhs-pc-web
params/payload: 请求参数(GET用params,POST用payload)
# 安装uv包管理器
curl -LsSf https://astral.sh/uv/install.sh | sh
# 克隆项目
git clone https://github.com/Cloxl/xhshow
cd xhshow
# 安装依赖
uv sync --dev
# 运行测试
uv run pytest tests/ -v
# 代码检查
uv run ruff check src/ tests/ --ignore=UP036,E501
# 代码格式化
uv run ruff format src/ tests/
# 构建包
uv build
# 创建功能分支
git checkout -b feat/your-feature
# 提交代码(遵循conventional commits规范)
git commit -m "feat(client): 添加新功能描述"
# 推送到远程
git push origin feat/your-feature
MIT