feat: 实现获取小红书首页 Feed 列表功能
- 添加 FeedsListAction 用于获取页面 window.__INITIAL_STATE__ 数据 - 定义完整的 Feed 数据结构,包含笔记、视频、用户信息等 - 实现 GetFeedsList 方法解析并返回 Feed 列表 - 添加单元测试验证数据获取和 JSON 序列化 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
83
xiaohongshu/types.go
Normal file
83
xiaohongshu/types.go
Normal file
@@ -0,0 +1,83 @@
|
||||
package xiaohongshu
|
||||
|
||||
// 小红书 Feed 相关的数据结构定义
|
||||
|
||||
// FeedResponse 表示从 __INITIAL_STATE__ 中获取的完整 Feed 响应
|
||||
type FeedResponse struct {
|
||||
Feed FeedData `json:"feed"`
|
||||
}
|
||||
|
||||
// FeedData 表示 feed 数据结构
|
||||
type FeedData struct {
|
||||
Feeds FeedsValue `json:"feeds"`
|
||||
}
|
||||
|
||||
// FeedsValue 表示 feeds 的值结构
|
||||
type FeedsValue struct {
|
||||
Value []Feed `json:"_value"`
|
||||
}
|
||||
|
||||
// Feed 表示单个 Feed 项目
|
||||
type Feed struct {
|
||||
XsecToken string `json:"xsecToken"`
|
||||
ID string `json:"id"`
|
||||
ModelType string `json:"modelType"`
|
||||
NoteCard NoteCard `json:"noteCard"`
|
||||
TrackID string `json:"trackId"`
|
||||
Ignore bool `json:"ignore"`
|
||||
Index int `json:"index"`
|
||||
Exposed bool `json:"exposed"`
|
||||
SSRRendered bool `json:"ssrRendered"`
|
||||
}
|
||||
|
||||
// NoteCard 表示笔记卡片信息
|
||||
type NoteCard struct {
|
||||
Type string `json:"type"`
|
||||
DisplayTitle string `json:"displayTitle"`
|
||||
User User `json:"user"`
|
||||
InteractInfo InteractInfo `json:"interactInfo"`
|
||||
Cover Cover `json:"cover"`
|
||||
Video *Video `json:"video,omitempty"` // 视频内容,可能为空
|
||||
}
|
||||
|
||||
// User 表示用户信息
|
||||
type User struct {
|
||||
UserID string `json:"userId"`
|
||||
Nickname string `json:"nickname"`
|
||||
NickName string `json:"nickName"`
|
||||
Avatar string `json:"avatar"`
|
||||
XsecToken string `json:"xsecToken"`
|
||||
}
|
||||
|
||||
// InteractInfo 表示互动信息
|
||||
type InteractInfo struct {
|
||||
Liked bool `json:"liked"`
|
||||
LikedCount string `json:"likedCount"`
|
||||
}
|
||||
|
||||
// Cover 表示封面信息
|
||||
type Cover struct {
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
URL string `json:"url"`
|
||||
FileID string `json:"fileId"`
|
||||
URLPre string `json:"urlPre"`
|
||||
URLDefault string `json:"urlDefault"`
|
||||
InfoList []ImageInfo `json:"infoList"`
|
||||
}
|
||||
|
||||
// ImageInfo 表示图片信息
|
||||
type ImageInfo struct {
|
||||
ImageScene string `json:"imageScene"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
// Video 表示视频信息
|
||||
type Video struct {
|
||||
Capa VideoCapability `json:"capa"`
|
||||
}
|
||||
|
||||
// VideoCapability 表示视频能力信息
|
||||
type VideoCapability struct {
|
||||
Duration int `json:"duration"` // 视频时长,单位秒
|
||||
}
|
||||
Reference in New Issue
Block a user