66
77
88def question_test (url ):
9-
109 question = Question (url )
1110
1211 # 获取该问题的标题
@@ -19,15 +18,17 @@ def question_test(url):
1918 followers_num = question .get_followers_num ()
2019 # 获取该问题所属话题
2120 topics = question .get_topics ()
21+ # 获取该问题被浏览次数
22+ visit_times = question .get_visit_times ()
2223 # 获取排名第一的回答
2324 top_answer = question .get_top_answer ()
2425 # 获取排名前十的十个回答
2526 top_answers = question .get_top_i_answers (10 )
2627 # 获取所有回答
2728 answers = question .get_all_answers ()
2829
29- print title # 输出:现实可以有多美好?
30- print detail
30+ print title # 输出:现实可以有多美好?
31+ print detail
3132 # 输出:
3233 # 本问题相对于“现实可以多残酷?传送门:现实可以有多残酷?
3334 # 题主: 昨天看了“现实可以有多残酷“。感觉不太好,所以我
@@ -36,49 +37,56 @@ def question_test(url):
3637 # 是“晒幸福“比赛。所以大家从“现实,实际”的角度出发,讲述自己的
3738 # 美好故事,让大家看看社会的冷和暖,能更加辨证地看待世界,是此
3839 # 题和彼题共同的“心愿“吧。
39- print answers_num # 输出:2441
40- print followers_num # 输出:26910
40+ print answers_num # 输出:2441
41+ print followers_num # 输出:26910
4142 for topic in topics :
42- print topic , # 输出:情感克制 现实 社会 个人经历
43- print top_answer # 输出:<zhihu.Answer instance at 0x7f8b6582d0e0>(Answer类对象)
44- print top_answers # 输出:<generator object get_top_i_answers at 0x7fed676eb320>(代表前十的Answer的生成器)
45- print answers # 输出:<generator object get_all_answer at 0x7f8b66ba30a0>(代表所有Answer的生成器)
43+ print topic , # 输出:情感克制 现实 社会 个人经历
44+ print visit_times # 输出: 该问题当前被浏览的次数
45+ print top_answer # 输出:<zhihu.Answer instance at 0x7f8b6582d0e0>(Answer类对象)
46+ print top_answers # 输出:<generator object get_top_i_answers at 0x7fed676eb320>(代表前十的Answer的生成器)
47+ print answers # 输出:<generator object get_all_answer at 0x7f8b66ba30a0>(代表所有Answer的生成器)
4648
4749
4850def answer_test (answer_url ):
49-
5051 answer = Answer (answer_url )
5152 # 获取该答案回答的问题
5253 question = answer .get_question ()
5354 # 获取该答案的作者
5455 author = answer .get_author ()
5556 # 获取该答案获得的赞同数
5657 upvote = answer .get_upvote ()
58+ # 获取改该答案所属问题被浏览次数
59+ visit_times = answer .get_visit_times ()
60+ # 获取所有给该答案点赞的用户信息
61+ voters = answer .get_voters ()
5762 # 把答案输出为txt文件
5863 answer .to_txt ()
5964 # 把答案输出为markdown文件
6065 answer .to_md ()
6166
62- print question
67+ print question
6368 # <zhihu.Question instance at 0x7f0b25d13f80>
6469 # 一个Question对象
65- print question .get_title () # 输出:现实可以有多美好?
66- print author
70+ print question .get_title () # 输出:现实可以有多美好?
71+ print author
6772 # <zhihu.User instance at 0x7f0b25425b90>
6873 # 一个User对象
69- print author .get_user_id () # 输出:田浩
70- print upvote # 输出:9320
74+ for voter in voters :
75+ print voter
76+ # 一个 User 对象
77+ print author .get_user_id () # 输出:田浩
78+ print upvote # 输出:9320
79+ print visit_times # 输出: 改答案所属问题被浏览次数
7180
7281
7382def user_test (user_url ):
74-
7583 user = User (user_url )
7684 # 获取用户ID
7785 user_id = user .get_user_id ()
7886 # 获取该用户的关注者人数
7987 followers_num = user .get_followers_num ()
8088 # 获取该用户关注的人数
81- followees_num = user .get_followees_num ()
89+ followees_num = user .get_followees_num ()
8290 # 获取该用户提问的个数
8391 asks_num = user .get_asks_num ()
8492 # 获取该用户回答的个数
@@ -101,14 +109,14 @@ def user_test(user_url):
101109 # 获取该用户的收藏夹
102110 collections = user .get_collections ()
103111
104- print user_id # 黄继新
105- print followers_num # 614840
106- print followees_num # 8408
107- print asks_num # 1323
108- print answers_num # 786
109- print collections_num # 44
110- print agree_num # 46387
111- print thanks_num # 11477
112+ print user_id # 黄继新
113+ print followers_num # 614840
114+ print followees_num # 8408
115+ print asks_num # 1323
116+ print answers_num # 786
117+ print collections_num # 44
118+ print agree_num # 46387
119+ print thanks_num # 11477
112120
113121 print followees
114122 # <generator object get_followee at 0x7ffcac3af050>
@@ -142,7 +150,6 @@ def user_test(user_url):
142150
143151
144152def collection_test (collection_url ):
145-
146153 collection = Collection (collection_url )
147154
148155 # 获取该收藏夹的创建者
@@ -154,18 +161,19 @@ def collection_test(collection_url):
154161 # 获取该收藏夹下的所有答案
155162 answers = collection .get_all_answers ()
156163
157- print creator
164+ print creator
158165 # <zhihu.User instance at 0x7fe1296f29e0>
159166 # 一个User对象
160- print creator .get_user_id () # 稷黍
161- print name # 给你一个不同的视角
167+ print creator .get_user_id () # 稷黍
168+ print name # 给你一个不同的视角
162169 print top_answers
163170 # <generator object get_top_i_answers at 0x7f378465dc80>
164171 # 代表前十个答案的生成器对象
165- print answers
172+ print answers
166173 # <generator object get_all_answer at 0x7fe12a29b280>
167174 # 代表所有答案的生成器对象
168175
176+
169177def test ():
170178 url = "http://www.zhihu.com/question/24269892"
171179 question = Question (url )
@@ -190,6 +198,7 @@ def test():
190198 answer .to_txt ()
191199 answer .to_md ()
192200
201+
193202def main ():
194203 url = "http://www.zhihu.com/question/24269892"
195204 question_test (url )
@@ -201,5 +210,7 @@ def main():
201210 collection_test (collection_url )
202211 test ()
203212
213+
204214if __name__ == '__main__' :
205- main ()
215+ main ()
216+
0 commit comments