Documentation ¶
Index ¶
- Variables
- func Init(cfgFile string)
- func SetSession(s *Session)
- type Answer
- func (a *Answer) GetAuthor() *User
- func (a *Answer) GetCollectedNum() int
- func (a *Answer) GetCommentsNum() int
- func (a *Answer) GetContent() string
- func (a *Answer) GetID() int
- func (a *Answer) GetQuestion() *Question
- func (a *Answer) GetUpvote() int
- func (a *Answer) GetVoters() []*User
- func (a *Answer) GetVotersN(n int) []*User
- func (a *Answer) String() string
- func (a *Answer) ToHtml(filename string) error
- func (a *Answer) ToMarkdown(filename string) error
- type Auth
- type Collection
- func (c *Collection) GetAnswers() []*Answer
- func (c *Collection) GetAnswersN(n int) []*Answer
- func (c *Collection) GetCreator() *User
- func (c *Collection) GetFollowers() []*User
- func (c *Collection) GetFollowersN(n int) []*User
- func (c *Collection) GetFollowersNum() int
- func (c *Collection) GetName() string
- func (c *Collection) GetQuestions() []*Question
- func (c *Collection) GetQuestionsN(n int) []*Question
- func (c *Collection) String() string
- type Logger
- func (logger *Logger) Debug(msg string, a ...interface{})
- func (logger *Logger) Error(msg string, a ...interface{})
- func (logger *Logger) Info(msg string, a ...interface{})
- func (logger *Logger) Success(msg string, a ...interface{})
- func (logger *Logger) Warn(msg string, a ...interface{})
- func (logger *Logger) Warning(msg string, a ...interface{})
- type Page
- type Question
- func (q *Question) GetAllAnswers() []*Answer
- func (q *Question) GetAnswersNum() int
- func (q *Question) GetDetail() string
- func (q *Question) GetFollowers() []*User
- func (q *Question) GetFollowersN(n int) []*User
- func (q *Question) GetFollowersNum() int
- func (q *Question) GetTitle() string
- func (q *Question) GetTopAnswer() *Answer
- func (q *Question) GetTopXAnswers(x int) []*Answer
- func (q *Question) GetTopics() []*Topic
- func (q *Question) GetVisitTimes() int
- func (q *Question) String() string
- type Session
- func (s *Session) Ajax(url string, body io.Reader, referer string) (*http.Response, error)
- func (s *Session) Get(url string) (*http.Response, error)
- func (s *Session) LoadConfig(cfg string)
- func (s *Session) Login() error
- func (s *Session) Post(url string, bodyType string, body io.Reader) (*http.Response, error)
- type Topic
- type User
- func (user *User) GetAgreeNum() int
- func (user *User) GetAnswers() []*Answer
- func (user *User) GetAnswersN(n int) []*Answer
- func (user *User) GetAnswersNum() int
- func (user *User) GetAsks() []*Question
- func (user *User) GetAsksN(n int) []*Question
- func (user *User) GetAsksNum() int
- func (user *User) GetAvatar() string
- func (user *User) GetAvatarWithSize(size string) string
- func (user *User) GetBio() string
- func (user *User) GetBusiness() string
- func (user *User) GetCollections() []*Collection
- func (user *User) GetCollectionsN(n int) []*Collection
- func (user *User) GetCollectionsNum() int
- func (user *User) GetDataID() string
- func (user *User) GetEducation() string
- func (user *User) GetFollowedColumnsNum() int
- func (user *User) GetFollowedTopics() []*Topic
- func (user *User) GetFollowedTopicsN(n int) []*Topic
- func (user *User) GetFollowedTopicsNum() int
- func (user *User) GetFollowees() []*User
- func (user *User) GetFolloweesN(n int) []*User
- func (user *User) GetFolloweesNum() int
- func (user *User) GetFollowers() []*User
- func (user *User) GetFollowersN(n int) []*User
- func (user *User) GetFollowersNum() int
- func (user *User) GetGender() string
- func (user *User) GetLikes() []*Answer
- func (user *User) GetLocation() string
- func (user *User) GetLogsNum() int
- func (user *User) GetPostsNum() int
- func (user *User) GetThanksNum() int
- func (user *User) GetUserID() string
- func (user *User) GetVotedAnswers() []*Answer
- func (user *User) GetWeiboURL() string
- func (user *User) IsAnonymous() bool
- func (user *User) String() string
Constants ¶
This section is empty.
Variables ¶
var (
ANONYMOUS = NewUser("", "匿名用户")
)
Functions ¶
Types ¶
type Answer ¶
type Answer struct { *Page // contains filtered or unexported fields }
Answer 是一个知乎的答案
func (*Answer) GetQuestion ¶
GetQuestion 返回该回答所属的问题,如果 NewAnswer 时 question 不为 nil,则直接返回该值; 否则会抓取页面并分析得到问题的链接和标题,再新建一个 Question 对象
func (*Answer) GetVotersN ¶
GetVotersN 返回 n 个点赞的用户,如果 n < 0,返回所有点赞的用户
func (*Answer) ToMarkdown ¶
ToMarkdown 把回答导出到 markdown 文件
type Auth ¶
type Auth struct { Account string `json:"account"` Password string `json:"password"` // contains filtered or unexported fields }
Auth 是用于登录的信息,保存了用户名和密码
type Collection ¶
type Collection struct { *Page // contains filtered or unexported fields }
Collection 是一个知乎的收藏夹页面
func NewCollection ¶
func NewCollection(link string, name string, creator *User) *Collection
NewCollection 创建一个收藏夹对象,返回 *Collection
func (*Collection) GetAnswersN ¶
func (c *Collection) GetAnswersN(n int) []*Answer
GetAnswersN 返回 n 个回答,如果 n < 0,返回所有回答
func (*Collection) GetFollowers ¶
func (c *Collection) GetFollowers() []*User
GetFollowers 返回关注该收藏夹的用户
func (*Collection) GetFollowersN ¶
func (c *Collection) GetFollowersN(n int) []*User
GetFollowersN 返回 n 个关注该收藏夹的用户,如果 n < 0,返回所有关注者
func (*Collection) GetFollowersNum ¶
func (c *Collection) GetFollowersNum() int
GetFollowersNum 返回收藏夹的关注者数量
func (*Collection) GetQuestions ¶
func (c *Collection) GetQuestions() []*Question
GetQuestions 返回收藏夹里所有的问题
func (*Collection) GetQuestionsN ¶
func (c *Collection) GetQuestionsN(n int) []*Question
GetQuestionsN 返回前 n 个问题,如果 n < 0,返回所有问题
func (*Collection) String ¶
func (c *Collection) String() string
type Logger ¶
type Logger struct {
Enabled bool
}
Logger 是一个简单的输出工具,可以输出不同颜色的信息 TODO simple level
type Page ¶
type Page struct { // Link 是该页面的链接 Link string // contains filtered or unexported fields }
ZhihuPage 是一个知乎页面,User, Question, Answer, Collection 的公共部分
type Question ¶
type Question struct { *Page // contains filtered or unexported fields }
Question 表示一个知乎问题,可以用于获取其标题、详情、答案等信息
func NewQuestion ¶
NewQuestion 通过给定的 URL 创建一个 Question 对象
func (*Question) GetAllAnswers ¶
GetAllAnswers 获取问题的所有答案
func (*Question) GetFollowersN ¶
GetFollowersN 返回 n 个关注者,如果 n < 0,返回所有关注者
func (*Question) GetFollowersNum ¶
GetFollowersNum 获取问题关注数量
func (*Question) GetTopXAnswers ¶
GetTopXAnswers 获取问题 Top X 的答案
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session 保持和知乎服务器的会话,用于向服务器发起请求获取 HTML 或 JSON 数据
func NewSession ¶
func NewSession() *Session
NewSession 创建并返回一个 *Session 对象, 这里没有初始化登录账号信息,账号信息用 `LoadConfig` 通过配置文件进行设置
func (*Session) LoadConfig ¶
LoadConfig 从配置文件中读取账号信息 配置文件 是 JSON 格式:
{ "account": "xyz@example.com", "password": "p@ssw0rd" }
type Topic ¶
type Topic struct { *Page // contains filtered or unexported fields }
func (*Topic) GetTopAuthors ¶
GetTopAuthors 返回最佳回答者,一般来说是 5 个
type User ¶
type User struct { *Page // contains filtered or unexported fields }
User 表示一个知乎用户
func NewUser ¶
NewUser 创建一个用户对象。 link 为空的时候表示匿名用户,此时 userId 仅允许 "匿名用户" 或 "知乎用户"; userId 可以为空,这种情况下调用 GetUserID 会去解析用户主页
func (*User) GetAnswersN ¶
GetAnswersN 返回用户前 n 个回答,如果 n < 0,返回所有回答
func (*User) GetAvatarWithSize ¶
GetAvatarWithSize 返回指定尺寸的的头像 URL,size 支持的值:s, xs, m, l, xl, hd, ""
func (*User) GetCollections ¶
func (user *User) GetCollections() []*Collection
GetCollections 返回用户的收藏夹
func (*User) GetCollectionsN ¶
func (user *User) GetCollectionsN(n int) []*Collection
GetCollectionsN 返回用户前 n 个收藏夹,如果 n < 0,返回所有收藏夹
func (*User) GetCollectionsNum ¶
GetCollectionsNum 返回用户的收藏夹数量
func (*User) GetFollowedColumnsNum ¶
GetFollowedColumnsNum 返回用户关注的专栏数量
func (*User) GetFollowedTopics ¶
GetFollowedTopics 返回用户关注的话题
func (*User) GetFollowedTopicsN ¶
GetFollowedTopicsN 返回用户前 n 个关注的话题,如果 n < 0,返回所有话题
func (*User) GetFollowedTopicsNum ¶
GetFollowedTopicsNum 返回用户关注的话题数量
func (*User) GetFolloweesN ¶
GetFolloweesN 返回前 n 个用户关注的人,如果 n < 0,返回所有关注的人
func (*User) GetFollowersN ¶
GetFollowersN 返回前 n 个粉丝,如果 n < 0,返回所有粉丝
func (*User) GetVotedAnswers ¶
GetVotedAnswers 是 GetLikes 的别名