|
1 | 1 | # -*- coding: utf-8 -*- |
2 | | -# from zhihu import Question |
3 | | -# from zhihu import Answer |
4 | | -# from zhihu import User |
| 2 | +from zhihu import Question |
| 3 | +from zhihu import Answer |
| 4 | +from zhihu import User |
5 | 5 | from zhihu import Collection |
6 | 6 |
|
7 | | -# url = "http://www.zhihu.com/question/24269892" |
8 | | -# question = Question(url) |
| 7 | +url = "http://www.zhihu.com/question/24269892" |
| 8 | +question = Question(url) |
9 | 9 |
|
10 | | -# # 获取该问题的标题 |
11 | | -# title = question.get_title() |
12 | | -# # 获取该问题的详细描述 |
13 | | -# detail = question.get_detail() |
14 | | -# # 获取回答个数 |
15 | | -# answer_num = question.get_answer_num() |
16 | | -# # 获取关注该问题的人数 |
17 | | -# follower_num = question.get_follower_num() |
18 | | -# # 获取该问题所属话题 |
19 | | -# topics = question.get_topics() |
20 | | -# # 获取排名第一的回答 |
21 | | -# top_answer = question.get_top_answer() |
22 | | -# # 获取所有回答 |
23 | | -# answers = question.get_all_answer() |
| 10 | +# 获取该问题的标题 |
| 11 | +title = question.get_title() |
| 12 | +# 获取该问题的详细描述 |
| 13 | +detail = question.get_detail() |
| 14 | +# 获取回答个数 |
| 15 | +answer_num = question.get_answer_num() |
| 16 | +# 获取关注该问题的人数 |
| 17 | +follower_num = question.get_follower_num() |
| 18 | +# 获取该问题所属话题 |
| 19 | +topics = question.get_topics() |
| 20 | +# 获取排名第一的回答 |
| 21 | +top_answer = question.get_top_answer() |
| 22 | +# 获取所有回答 |
| 23 | +answers = question.get_all_answer() |
24 | 24 |
|
25 | | -# print title # 输出:现实可以有多美好? |
26 | | -# print detail |
27 | | -# # 输出: |
28 | | -# # 本问题相对于“现实可以多残酷?传送门:现实可以有多残酷? |
29 | | -# # 题主: 昨天看了“现实可以有多残酷“。感觉不太好,所以我 |
30 | | -# # 开了这个问题以相对应,希望能够“中和一下“。和那个问题题主不想 |
31 | | -# # 把它变成“比惨大会“一样,我也不想把这个变成“鸡汤故事会“,或者 |
32 | | -# # 是“晒幸福“比赛。所以大家从“现实,实际”的角度出发,讲述自己的 |
33 | | -# # 美好故事,让大家看看社会的冷和暖,能更加辨证地看待世界,是此 |
34 | | -# # 题和彼题共同的“心愿“吧。 |
35 | | -# print answer_num # 输出:2441 |
36 | | -# print follower_num # 输出:26910 |
37 | | -# for topic in topics: |
38 | | -# print topic , # 输出:情感克制 现实 社会 个人经历 |
39 | | -# print top_answer # 输出:<zhihu.Answer instance at 0x7f8b6582d0e0>(Answer类对象) |
40 | | -# print answers # 输出:<generator object get_all_answer at 0x7f8b66ba30a0>(代表所有Answer的生成器) |
| 25 | +print title # 输出:现实可以有多美好? |
| 26 | +print detail |
| 27 | +# 输出: |
| 28 | +# 本问题相对于“现实可以多残酷?传送门:现实可以有多残酷? |
| 29 | +# 题主: 昨天看了“现实可以有多残酷“。感觉不太好,所以我 |
| 30 | +# 开了这个问题以相对应,希望能够“中和一下“。和那个问题题主不想 |
| 31 | +# 把它变成“比惨大会“一样,我也不想把这个变成“鸡汤故事会“,或者 |
| 32 | +# 是“晒幸福“比赛。所以大家从“现实,实际”的角度出发,讲述自己的 |
| 33 | +# 美好故事,让大家看看社会的冷和暖,能更加辨证地看待世界,是此 |
| 34 | +# 题和彼题共同的“心愿“吧。 |
| 35 | +print answer_num # 输出:2441 |
| 36 | +print follower_num # 输出:26910 |
| 37 | +for topic in topics: |
| 38 | + print topic , # 输出:情感克制 现实 社会 个人经历 |
| 39 | +print top_answer # 输出:<zhihu.Answer instance at 0x7f8b6582d0e0>(Answer类对象) |
| 40 | +print answers # 输出:<generator object get_all_answer at 0x7f8b66ba30a0>(代表所有Answer的生成器) |
41 | 41 |
|
42 | 42 |
|
43 | | -# answer_url = "http://www.zhihu.com/question/24269892/answer/29960616" |
44 | | -# answer = Answer(answer_url) |
45 | | -# # 获取该答案回答的问题 |
46 | | -# question = answer.get_question() |
47 | | -# # 获取该答案的作者 |
48 | | -# author = answer.get_author() |
49 | | -# # 获取该答案获得的赞同数 |
50 | | -# upvote = answer.get_upvote() |
51 | | -# # 把答案输出为txt文件 |
52 | | -# answer.to_txt() |
53 | | -# # 把答案输出为markdown文件 |
54 | | -# answer.to_md() |
| 43 | +answer_url = "http://www.zhihu.com/question/24269892/answer/29960616" |
| 44 | +answer = Answer(answer_url) |
| 45 | +# 获取该答案回答的问题 |
| 46 | +question = answer.get_question() |
| 47 | +# 获取该答案的作者 |
| 48 | +author = answer.get_author() |
| 49 | +# 获取该答案获得的赞同数 |
| 50 | +upvote = answer.get_upvote() |
| 51 | +# 把答案输出为txt文件 |
| 52 | +answer.to_txt() |
| 53 | +# 把答案输出为markdown文件 |
| 54 | +answer.to_md() |
55 | 55 |
|
56 | | -# print question |
57 | | -# # <zhihu.Question instance at 0x7f0b25d13f80> |
58 | | -# # 一个Question对象 |
59 | | -# print question.get_title() # 输出:现实可以有多美好? |
60 | | -# print author |
61 | | -# # <zhihu.User instance at 0x7f0b25425b90> |
62 | | -# # 一个User对象 |
63 | | -# print author.get_user_id() # 输出:田浩 |
64 | | -# print upvote # 输出:9320 |
| 56 | +print question |
| 57 | +# <zhihu.Question instance at 0x7f0b25d13f80> |
| 58 | +# 一个Question对象 |
| 59 | +print question.get_title() # 输出:现实可以有多美好? |
| 60 | +print author |
| 61 | +# <zhihu.User instance at 0x7f0b25425b90> |
| 62 | +# 一个User对象 |
| 63 | +print author.get_user_id() # 输出:田浩 |
| 64 | +print upvote # 输出:9320 |
65 | 65 |
|
66 | 66 |
|
67 | | -# user_url = "http://www.zhihu.com/people/jixin" |
68 | | -# user = User(user_url) |
69 | | -# # 获取用户ID |
70 | | -# user_id = user.get_user_id() |
71 | | -# # 获取该用户的关注者人数 |
72 | | -# follower_num = user.get_follower_num() |
73 | | -# # 获取该用户关注的人数 |
74 | | -# followee_num =user.get_followee_num() |
75 | | -# # 获取该用户提问的个数 |
76 | | -# ask_num = user.get_ask_num() |
77 | | -# # 获取该用户回答的个数 |
78 | | -# answer_num = user.get_answer_num() |
79 | | -# # 获取该用户收藏夹个数 |
80 | | -# collection_num = user.get_collection_num() |
81 | | -# # 获取该用户获得的赞同数 |
82 | | -# agree_num = user.get_agree_num() |
83 | | -# # 获取该用户获得的感谢数 |
84 | | -# thanks_num = user.get_thanks_num() |
| 67 | +user_url = "http://www.zhihu.com/people/jixin" |
| 68 | +user = User(user_url) |
| 69 | +# 获取用户ID |
| 70 | +user_id = user.get_user_id() |
| 71 | +# 获取该用户的关注者人数 |
| 72 | +follower_num = user.get_follower_num() |
| 73 | +# 获取该用户关注的人数 |
| 74 | +followee_num =user.get_followee_num() |
| 75 | +# 获取该用户提问的个数 |
| 76 | +ask_num = user.get_ask_num() |
| 77 | +# 获取该用户回答的个数 |
| 78 | +answer_num = user.get_answer_num() |
| 79 | +# 获取该用户收藏夹个数 |
| 80 | +collection_num = user.get_collection_num() |
| 81 | +# 获取该用户获得的赞同数 |
| 82 | +agree_num = user.get_agree_num() |
| 83 | +# 获取该用户获得的感谢数 |
| 84 | +thanks_num = user.get_thanks_num() |
85 | 85 |
|
86 | | -# # 获取该用户关注的人 |
87 | | -# followees = user.get_followee() |
88 | | -# # 获取关注该用户的人 |
89 | | -# followers = user.get_follower() |
90 | | -# # 获取该用户提的问题 |
91 | | -# asks = user.get_ask() |
92 | | -# # 获取该用户回答的问题的答案 |
93 | | -# answers = user.get_answer() |
94 | | -# # 获取该用户的收藏夹 |
95 | | -# collections = user.get_collection() |
| 86 | +# 获取该用户关注的人 |
| 87 | +followees = user.get_followee() |
| 88 | +# 获取关注该用户的人 |
| 89 | +followers = user.get_follower() |
| 90 | +# 获取该用户提的问题 |
| 91 | +asks = user.get_ask() |
| 92 | +# 获取该用户回答的问题的答案 |
| 93 | +answers = user.get_answer() |
| 94 | +# 获取该用户的收藏夹 |
| 95 | +collections = user.get_collection() |
96 | 96 |
|
97 | | -# print user_id # 黄继新 |
98 | | -# print follower_num # 614840 |
99 | | -# print followee_num # 8408 |
100 | | -# print ask_num # 1323 |
101 | | -# print answer_num # 786 |
102 | | -# print collection_num # 44 |
103 | | -# print agree_num # 46387 |
104 | | -# print thanks_num # 11477 |
| 97 | +print user_id # 黄继新 |
| 98 | +print follower_num # 614840 |
| 99 | +print followee_num # 8408 |
| 100 | +print ask_num # 1323 |
| 101 | +print answer_num # 786 |
| 102 | +print collection_num # 44 |
| 103 | +print agree_num # 46387 |
| 104 | +print thanks_num # 11477 |
105 | 105 |
|
106 | | -# print followees |
107 | | -# # <generator object get_followee at 0x7ffcac3af050> |
108 | | -# # 代表所有该用户关注的人的生成器对象 |
109 | | -# print followers |
110 | | -# # <generator object get_follower at 0x7ffcac3af0f0> |
111 | | -# # 代表所有关注该用户的人的生成器对象 |
112 | | -# print asks |
113 | | -# # <generator object get_ask at 0x7ffcab9db780> |
114 | | -# # 代表该用户提的所有问题的生成器对象 |
115 | | -# print answers |
116 | | -# # <generator object get_answer at 0x7ffcab9db7d0> |
117 | | -# # 代表该用户回答的所有问题的答案的生成器对象 |
118 | | -# print collections |
119 | | -# # <generator object get_collection at 0x7ffcab9db820> |
120 | | -# # 代表该用户收藏夹的生成器对象 |
| 106 | +print followees |
| 107 | +# <generator object get_followee at 0x7ffcac3af050> |
| 108 | +# 代表所有该用户关注的人的生成器对象 |
| 109 | +print followers |
| 110 | +# <generator object get_follower at 0x7ffcac3af0f0> |
| 111 | +# 代表所有关注该用户的人的生成器对象 |
| 112 | +print asks |
| 113 | +# <generator object get_ask at 0x7ffcab9db780> |
| 114 | +# 代表该用户提的所有问题的生成器对象 |
| 115 | +print answers |
| 116 | +# <generator object get_answer at 0x7ffcab9db7d0> |
| 117 | +# 代表该用户回答的所有问题的答案的生成器对象 |
| 118 | +print collections |
| 119 | +# <generator object get_collection at 0x7ffcab9db820> |
| 120 | +# 代表该用户收藏夹的生成器对象 |
121 | 121 |
|
122 | 122 |
|
123 | 123 | collection_url = "http://www.zhihu.com/collection/36750683" |
|
0 commit comments