美文网首页Go语言Go 语言学习专栏 Golang
『简书API:Goquery 用法讲解(3):视频版』

『简书API:Goquery 用法讲解(3):视频版』

作者: 谢小路 | 来源:发表于2018-04-13 00:59 被阅读147次
    goquery

    大家好,我是谢伟,是一名程序员。

    简书API: Jianshu-go

    历史文章:

    1. 『简书API : jianshu 基于 golang (1)』

    2. 『简书API:jianshu 基于golang -- 用法介绍 (2)』

    这是这个项目中使用到的第三方库 goquery 的用法介绍:视频版。

    主要是讲解 goquery 的两个API:

    1. Document

    2. Selection

    Document:

    表示HTML document, 传入的参数可以是文件、httpResponse、url 等,对应调用不同的方法:

    1. func CloneDocument(doc *Document) *Document

    2. func NewDocument(url string) (*Document, error)

    3. func NewDocumentFromNode(root *html.Node) *Document

    4. func NewDocumentFromReader(r io.Reader) (*Document, error)

    5. func NewDocumentFromResponse(res *http.Response) (*Document, error)

    Selection:

    表示DOM 各节点的集合,可以使用CSS 选择器,从源代码中获取到需要的信息。

    主要的几个方法是:

    1、func (s *Selection) Attr(attrName string) (val string, exists bool)

    2、func (s *Selection) AttrOr(attrName, defaultValue string) string

    3、func (s *Selection) Each(f func(int, *Selection)) *Selection

    4、func (s *Selection) EachWithBreak(f func(int, *Selection) bool) *Selection

    5、func (s *Selection) Eq(index int) *Selection

    6、func (s *Selection) Filter(selector string) *Selection

    7、func (s *Selection) FilterFunction(f func(int, *Selection) bool) *Selection

    8、func (s *Selection) FilterMatcher(m Matcher) *Selection

    9、func (s *Selection) FilterNodes(nodes ...*html.Node) *Selection

    10、func (s *Selection) FilterSelection(sel *Selection) *Selection

    11、func (s *Selection) Find(selector string) *Selection

    12、func (s *Selection) FindMatcher(m Matcher) *Selection

    13、func (s *Selection) FindNodes(nodes ...*html.Node) *Selection

    14、func (s *Selection) FindSelection(sel *Selection) *Selection

    15、func (s *Selection) First() *Selection

    16、func (s *Selection) Get(index int) *html.Node

    17、func (s *Selection) Has(selector string) *Selection

    18、func (s *Selection) HasClass(class string) bool

    看文档 :goquery doc 要注意对应的函数的输入和输出。

    学会核心的几个,当对使用不清楚的方法,正确的做法是,编写简单的代码实现下。

    如何实现接口:user

    1、GetUserID 获取用户ID

    2、GetUserLink 获取用户主页URL

    3、GetUserGender 获取用户性别

    4、GetFollowNumber 获取用户关注数

    5、GetFollowerNumber 获取用户粉丝数

    6、GetPassageNumber 获取用户文章书面

    7、GetWriteNumber 获取用户写的字数

    8、GetLikeNumber 获取用户得到的喜欢的数目

    9、GetHomePagePassage 获取用户主页文章信息

    10、GetPersonalDetail 获取用户个人介绍

    11、GetTwitterInfo 获取用户微博地址

    12、GetLikedNotes 获取作者喜欢的文章信息

    13、GetSubscription 获取作者关注的专题/文集/连载

    14、GetLatestActice 获取作者最新动态

    15、GetLatestCommented 获取作者最新评论

    16、GetHotPassage 获取作者热门文章

    详情观看视频:


    Goquery 用法讲解

    百度网盘:goquery视频 密码:z55v

    感兴趣的话,我会多录制几个:

    视频有瑕疵,我正在改进,谢谢。

    相关文章

      网友评论

      本文标题:『简书API:Goquery 用法讲解(3):视频版』

      本文链接:https://www.haomeiwen.com/subject/zdeqkftx.html