# 小红书搜索 API 文档 ## 函数 ```python from script.search import search_xiaohongshu data = search_xiaohongshu(keyword, **options) ``` ## 参数 | 参数 | 类型 | 默认值 | 说明 | |------|------|--------|------| | **keyword** | str | 必填 | 搜索关键词 | | content_type | str | "不限" | 内容类型:不限、视频、图文 | | sort_type | str | "综合" | 排序:综合、最新、最多点赞、最多评论 | | publish_time | str | "不限" | 时间:不限、一天内、一周内、半年内 | | page | int | 1 | 页码(自动翻页) | | force | bool | False | 强制刷新 | ## 返回值 ```python { "search_params": {...}, # 搜索参数 "has_more": True, # 是否有更多 "next_cursor": "...", # 下一页游标 "notes": [...] # 笔记列表 } ``` ### 笔记字段 | 字段 | 说明 | |------|------| | channel_content_id | 笔记ID | | title | 标题 | | desc | 摘要 | | channel_account_name | 作者 | | like_count | 点赞数 | | comment_count | 评论数 | | collect_count | 收藏数 | | images | 图片列表 | | link | 链接 | ## 使用示例 ### 基本搜索 ```python from script.search import search_xiaohongshu data = search_xiaohongshu("产品测试") for note in data['notes']: print(f"{note['title']} - {note['like_count']} 赞") ``` ### 带参数搜索 ```python data = search_xiaohongshu( keyword="产品测试", content_type="视频", sort_type="最新", publish_time="一周内" ) ``` ### 翻页(自动处理) ```python # 直接指定页码即可 page1 = search_xiaohongshu("产品测试", page=1) page2 = search_xiaohongshu("产品测试", page=2) page3 = search_xiaohongshu("产品测试", page=3) ``` ### 强制刷新 ```python data = search_xiaohongshu("产品测试", force=True) ``` ## 内部特性 - ✅ 自动重试(最多3次) - ✅ 自动缓存(默认开启) - ✅ 自动保存(后台完成) - ✅ 超时保护(30秒)