试图构建一个更加简洁、优雅的、Pythonic 的知乎 API。
- Python3.x
- Requests
- BeautifulSoup4
git clone git@github.com:lzjun567/zhihu-api.git
cd zhihu-api
pip install .
>>> from zhihu.zhihu import Zhihu
>>> zhihu = Zhihu()
>>> zhihu.user(profile_url="https://www.zhihu.com/people/xiaoxiaodouzi")
{'avatar_url_template': 'https://pic1.zhimg.com/v2-ca13758626bd7367febde704c66249ec_{size}.jpg',
'badge': [],
'name': '我是小号',
'headline': '程序员',
'gender': -1,
'user_type': 'people',
'is_advertiser': False,
'avatar_url': 'https://pic1.zhimg.com/v2-ca13758626bd7367febde704c66249ec_is.jpg',
'url': 'http://www.zhihu.com/api/v4/people/1da75b85900e00adb072e91c56fd9149', 'type': 'people',
'url_token': 'xiaoxiaodouzi',
'id': '1da75b85900e00adb072e91c56fd9149',
'is_org': False}
# 还可以用
>>> zhihu.user(user_slug="xiaoxiaodouzi")
>>> zhihu.send_message("你好,问候3", user_id="1da75b85900e00adb072e91c56fd9149")
# 还支持 user_slug
>>> zhihu.send_message("你好,问候2", user_slug="xiaoxiaodouzi")
# 还支持 profile_url
>>> zhihu.zhihu.send_message("你好,问候1", profile_url="https://www.zhihu.com/people/xiaoxiaodouzi")
>>> zhihu.follow(profile_url="https://www.zhihu.com/people/gao-yu-dong-41")
{"follower_count": 6}
>>> zhihu.follow(user_slug="xiaoxiaodouzi")
{"follower_count": 6}
>>> from zhihu import Answer
>>> data = Answer(id=14005147).vote_up()
>>> data
>>> {"voting": 1, "voteup_count": 314}
>>> data = Answer(url="https://www.zhihu.com/question/19761434/answer/14005147").vote_up()
vote_down
vote_neutral
- 文章点赞
- ...
欢迎 PR, 所有贡献者都将出现在这里
- @BigBorg
群已经加不进,可以先加微信:lzjun567 拉你入群