Skip to content

Commit b22b812

Browse files
committed
Merge pull request egrcc#7 from lufo816/master
fix bug and add new function
2 parents 8dc0130 + e83acc9 commit b22b812

File tree

3 files changed

+307
-292
lines changed

3 files changed

+307
-292
lines changed

README.rst

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Question 代表一个问题,处理知乎问题相关操作。创建一个 Ques
9393
9494
url = "http://www.zhihu.com/question/24269892"
9595
question = Question(url)
96-
96+
9797
# 获取该问题的标题
9898
title = question.get_title()
9999
# 获取该问题的详细描述
@@ -104,15 +104,17 @@ Question 代表一个问题,处理知乎问题相关操作。创建一个 Ques
104104
followers_num = question.get_followers_num()
105105
# 获取该问题所属话题
106106
topics = question.get_topics()
107+
# 获取该问题被浏览次数
108+
visit_times = question.get_visit_times()
107109
# 获取排名第一的回答
108110
top_answer = question.get_top_answer()
109111
# 获取排名前十的十个回答
110112
top_answers = question.get_top_i_answers(10)
111113
# 获取所有回答
112114
answers = question.get_all_answers()
113-
114-
print title # 输出:现实可以有多美好?
115-
print detail
115+
116+
print title # 输出:现实可以有多美好?
117+
print detail
116118
# 输出:
117119
# 本问题相对于“现实可以多残酷?传送门:现实可以有多残酷?
118120
# 题主: 昨天看了“现实可以有多残酷“。感觉不太好,所以我
@@ -121,19 +123,14 @@ Question 代表一个问题,处理知乎问题相关操作。创建一个 Ques
121123
# 是“晒幸福“比赛。所以大家从“现实,实际”的角度出发,讲述自己的
122124
# 美好故事,让大家看看社会的冷和暖,能更加辨证地看待世界,是此
123125
# 题和彼题共同的“心愿“吧。
124-
print answers_num # 输出:2441
125-
print followers_num # 输出:26910
126+
print answers_num # 输出:2441
127+
print followers_num # 输出:26910
126128
for topic in topics:
127-
print topic , # 输出:情感克制 现实 社会 个人经历
128-
print top_answer
129-
# 输出:<zhihu.Answer instance at 0x7f8b6582d0e0>
130-
# 一个Answer类对象
131-
print top_answers
132-
# 输出:<generator object get_top_i_answers at 0x7fed676eb320>
133-
# 代表前十的Answer的生成器
134-
print answers
135-
# 输出:<generator object get_all_answer at 0x7f8b66ba30a0>
136-
# 代表所有Answer的生成器
129+
print topic, # 输出:情感克制 现实 社会 个人经历
130+
print visit_times # 输出: 该问题当前被浏览的次数
131+
print top_answer # 输出:<zhihu.Answer instance at 0x7f8b6582d0e0>(Answer类对象)
132+
print top_answers # 输出:<generator object get_top_i_answers at 0x7fed676eb320>(代表前十的Answer的生成器)
133+
print answers # 输出:<generator object get_all_answer at 0x7f8b66ba30a0>(代表所有Answer的生成器)
137134
138135
139136
Answer:获取答案信息
@@ -163,20 +160,28 @@ Answer 代表了一个答案,处理知乎答案相关操作。创建一个 Ans
163160
author = answer.get_author()
164161
# 获取该答案获得的赞同数
165162
upvote = answer.get_upvote()
163+
# 获取改该答案所属问题被浏览次数
164+
visit_times = answer.get_visit_times()
165+
# 获取所有给该答案点赞的用户信息
166+
voters = answer.get_voters()
166167
# 把答案输出为txt文件
167168
answer.to_txt()
168169
# 把答案输出为markdown文件
169170
answer.to_md()
170-
171-
print question
171+
172+
print question
172173
# <zhihu.Question instance at 0x7f0b25d13f80>
173174
# 一个Question对象
174-
print question.get_title() # 输出:现实可以有多美好?
175-
print author
175+
print question.get_title() # 输出:现实可以有多美好?
176+
print author
176177
# <zhihu.User instance at 0x7f0b25425b90>
177178
# 一个User对象
178-
print author.get_user_id() # 输出:田浩
179-
print upvote # 输出:9320
179+
for voter in voters:
180+
print voter
181+
# 一个 User 对象
182+
print author.get_user_id() # 输出:田浩
183+
print upvote # 输出:9320
184+
print visit_times # 输出: 改答案所属问题被浏览次数
180185
181186
182187
User:获取用户信息

test.py

100644100755
Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77

88
def 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

4850
def 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

7382
def 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

144152
def 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+
169177
def 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+
193202
def 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+
204214
if __name__ == '__main__':
205-
main()
215+
main()
216+

0 commit comments

Comments
 (0)