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,51 @@ 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 ()
5760 # 把答案输出为txt文件
5861 answer .to_txt ()
5962 # 把答案输出为markdown文件
6063 answer .to_md ()
6164
62- print question
65+ print question
6366 # <zhihu.Question instance at 0x7f0b25d13f80>
6467 # 一个Question对象
65- print question .get_title () # 输出:现实可以有多美好?
66- print author
68+ print question .get_title () # 输出:现实可以有多美好?
69+ print author
6770 # <zhihu.User instance at 0x7f0b25425b90>
6871 # 一个User对象
69- print author .get_user_id () # 输出:田浩
70- print upvote # 输出:9320
72+ print author .get_user_id () # 输出:田浩
73+ print upvote # 输出:9320
74+ print visit_times # 输出: 改答案所属问题被浏览次数
7175
7276
7377def user_test (user_url ):
74-
7578 user = User (user_url )
7679 # 获取用户ID
7780 user_id = user .get_user_id ()
7881 # 获取该用户的关注者人数
7982 followers_num = user .get_followers_num ()
8083 # 获取该用户关注的人数
81- followees_num = user .get_followees_num ()
84+ followees_num = user .get_followees_num ()
8285 # 获取该用户提问的个数
8386 asks_num = user .get_asks_num ()
8487 # 获取该用户回答的个数
@@ -101,14 +104,14 @@ def user_test(user_url):
101104 # 获取该用户的收藏夹
102105 collections = user .get_collections ()
103106
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
107+ print user_id # 黄继新
108+ print followers_num # 614840
109+ print followees_num # 8408
110+ print asks_num # 1323
111+ print answers_num # 786
112+ print collections_num # 44
113+ print agree_num # 46387
114+ print thanks_num # 11477
112115
113116 print followees
114117 # <generator object get_followee at 0x7ffcac3af050>
@@ -142,7 +145,6 @@ def user_test(user_url):
142145
143146
144147def collection_test (collection_url ):
145-
146148 collection = Collection (collection_url )
147149
148150 # 获取该收藏夹的创建者
@@ -154,18 +156,19 @@ def collection_test(collection_url):
154156 # 获取该收藏夹下的所有答案
155157 answers = collection .get_all_answers ()
156158
157- print creator
159+ print creator
158160 # <zhihu.User instance at 0x7fe1296f29e0>
159161 # 一个User对象
160- print creator .get_user_id () # 稷黍
161- print name # 给你一个不同的视角
162+ print creator .get_user_id () # 稷黍
163+ print name # 给你一个不同的视角
162164 print top_answers
163165 # <generator object get_top_i_answers at 0x7f378465dc80>
164166 # 代表前十个答案的生成器对象
165- print answers
167+ print answers
166168 # <generator object get_all_answer at 0x7fe12a29b280>
167169 # 代表所有答案的生成器对象
168170
171+
169172def test ():
170173 url = "http://www.zhihu.com/question/24269892"
171174 question = Question (url )
@@ -190,6 +193,7 @@ def test():
190193 answer .to_txt ()
191194 answer .to_md ()
192195
196+
193197def main ():
194198 url = "http://www.zhihu.com/question/24269892"
195199 question_test (url )
@@ -201,5 +205,6 @@ def main():
201205 collection_test (collection_url )
202206 test ()
203207
208+
204209if __name__ == '__main__' :
205210 main ()
0 commit comments