目的和准备
目的:
为了知道自己歌单中每首歌的评论,然后通过歌曲id来检索这首歌的所有评论,并且想熟悉运用golang中的channel以及整个爬虫架构
准备:
语言:golang
编辑器: goland
处理:goquery/正则
存储:mysql(elasticsearch)
V1版本(单机版,mysql存储)
models
评论struct[comment.go]
首先通过查看某一首音乐的请求获取到 ajax(eg:https://music.163.com/weapi/v1/resource/comments/R_SO_4_340394?csrf_token=)
请求的json
通过返回的json
数据构造出struct
//每首歌的评论
type Commentt struct {
Id int64
IsMusician bool `json:"isMusician"`
UserId int32 `json:"userId"`
//TopComments []string `json:"topComments";gorm:"-"`
MoreHot bool `json:"moreHot"`
HotComments []*HotComments `json:"hotComments"`
Code int `json:"code"`
Comments []*Comments `json:"comments"`
Total int64 `json:"total"`
More bool `json:"more"`
SongId string
}
//具体到每条评论(普通评论)
type Comments struct {
Id int64
User *User `json:"user"`
BeReplied []*BeReplied `json:"-"`
Time int64 `json:"time"`
LikedCount int `json:"likedCount"`
Liked bool `json:"liked"`
CommentId int64 `json:"commentId"`
Content string `json:"content";gorm:"type:longtext"`
IsRemoveHotComment bool `json:"isRemoveHotComment"`
Commentt *Commentt
CommenttID int64
}
//热门评论
type HotComments struct {
Id int64
User *User `json:"user"`
BeReplied []*BeReplied `json:"-"`
Time int64 `json:"time"`
LikedCount int `json:"likedCount"`
Liked bool `json:"liked"`
CommentId int64 `json:"commentId"`
Content string `json:"content";gorm:"type:longtext"`
Commentt *Commentt
CommenttID int64
}
//评论的用户信息
type User struct {
Id int64
LocationInfo *LocationInfo `json:"-"`
UserType int `json:"userType"`
ExpertTags *ExpertTag `json:"-"`
UserId int64 `json:"userId"`
NickName string `json:"nickName"`
Experts *Expert `json:"-"`
AuthStatus int `json:"authStatus"`
RemarkName *RemarkName `json:"-"`
AvatarUrl string `json:"avatarUrl"`
VipType int `json:"vipType"`
Comments *Comments
CommentsID int64
}
//答复用户的评论信息
type BeReplied struct {
Id int64
User *User `json:"-"`
UserID int64
Content string `json:"content"`
Status int `json:"status"`
CommentsID int64
HotCommentsID int64
}
type LocationInfo struct {
}
type ExpertTag struct {
}
type Expert struct {
}
type RemarkName struct {
}
然后又查看了歌单信息看一了下网页Dom
结构构造出如下struct
歌曲列表struct[songList.go]
type Song struct {
Id int64
SongUrlId string
SongId string
Title string
DownloadUrl string
UserId string
}
type PlayList struct {
Id int64
UserId string
Songs []Song
}
然后又找了一下歌曲下载的接口发现只能在pc端下载,于是在一篇博客中找到了一些关于golang爬取网易云音乐的具体实现点击此处
歌曲下载struct[download.go]
type DownloadData struct {
Data []*Data `json:"data"`
Code int `json:"code"`
}
type Data struct {
Id int64 `json:"id"`
Url string `json:"url"`
Br int64 `json:"br"`
Md5 string `json:"md_5"`
Code int `json:"code"`
Expi int `json:"expi"`
Type string `json:"type"`
Gain float64 `json:"gain"`
Fee int `json:"fee"`
Uf *Uf `json:"-"`
Payed int `json:"payed"`
Flag int `json:"flag"`
CanExtend bool `json:"can_extend"`
}
type Uf struct {
}
推荐一个很好用的json
转struct
工具
以上就是所有数据库表