Project introduction

Zhihu API For Humans Based on Python3

precondition

  • Python3.x
  • Requests2
  • BeautifulSoup4

The installation

[email protected]:lzjun567/zhihu-api.git
cd  zhihu-api
pip install -r requirement.txtCopy the code

Use the API

Get user information: zhihu.user(id)

When you obtain user information, you can receive user profile_URL or user name user_slug

>>> from zhihu import Zhihu >>> zhihu = Zhihu() >>> zhihu.user(profile_url="https://www.zhihu.com/people/xiaoxiaodouzi")  >>> zhihu.user(user_slug="xiaoxiaodouzi") {'avatar_url_template': 'https://pic1.zhimg.com/v2-ca13758626bd7367febde704c66249ec_ {size}. JPG', 'badge' : [], 'name' : 'I am a small' 'headline' : 'Programmer ', '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}Copy the code

Send a private message: zhihu.send_message(id)

When you obtain user information, you can receive user profile_URL, user name user_slug, or user ID

> > > zhihu. Send_message (" 1 "hello, regards, profile_url =" https://www.zhihu.com/people/xiaoxiaodouzi ") {' sender ': {'avatar_url_template': 'https://pic3.zhimg.com/ca6bf4bb82d9cf152b618edcbda01606_{size}.jpg', 'badge': [], 'name': 'zhijun liu', 'is_advertiser': False, 'url': 'http://www.zhihu.com/api/v4/people/ba286d02fd9701a446d68ba85d0755c0', 'url_token': 'zhijun-liu', 'user_type': Headline: 'People ',' Avatar_url ': 'https://pic3.zhimg.com/ca6bf4bb82d9cf152b618edcbda01606_is.jpg', 'is_org': False, 'gender': 1, 'type': 'people', 'id': 'ba286d02fd9701a446d68ba85d0755c0'} 'url' : ', 'has_read: False,' content ':' hello, greetings from 1 ', 'receiver' : {'avatar_url_template': 'https://pic1.zhimg.com/v2-ca13758626bd7367febde704c66249ec_{size}.jpg', 'badge': [], 'name': 'I am the trumpet ', 'is_advertiser': False,' URL ': 'http://www.zhihu.com/api/v4/people/1da75b85900e00adb072e91c56fd9149', 'url_token': 'xiaoxiaodouzi', 'user_type': 'people', 'headline': 'programmer ', 'avatar_url': 'https://pic1.zhimg.com/v2-ca13758626bd7367febde704c66249ec_is.jpg', 'is_org': False, 'gender': -1, 'type': 'people', 'id': '1da75b85900e00adb072e91c56fd9149'}, 'created_time': 1492318772, 'type': 'message', 'id': } >>> zhihu. Send_message (" hello, hello 2", user_slug="xiaoxiaodouzi") {'sender': {'avatar_url_template': 'https://pic3.zhimg.com/ca6bf4bb82d9cf152b618edcbda01606_{size}.jpg', 'name': 'zhijun liu', 'is_advertiser': False, 'url': 'http://www.zhihu.com/api/v4/people/ba286d02fd9701a446d68ba85d0755c0', 'badge': [], 'user_type': 'people', 'url_token': 'zhijun-liu', 'Headline ': 'https://pic3.zhimg.com/ca6bf4bb82d9cf152b618edcbda01606_is.jpg', 'is_org': False, 'gender': 1, 'type': 'people', 'id': 'ba286d02fd9701a446d68ba85d0755c0'} 'url' : ', 'has_read: False,' content ':' hello, greetings from 2 ', 'receiver' : {'avatar_url_template': 'https://pic1.zhimg.com/v2-ca13758626bd7367febde704c66249ec_{size}.jpg', 'name': : 'I am a small', 'is_advertiser' False, 'url' : 'http://www.zhihu.com/api/v4/people/1da75b85900e00adb072e91c56fd9149', 'badge' : [], 'user_type' : 'people' and 'url_token' : 'xiaoxiaodouzi', 'headline' : 'programmers',' avatar_url ': 'https://pic1.zhimg.com/v2-ca13758626bd7367febde704c66249ec_is.jpg', 'is_org': False, 'gender': -1, 'type': 'people', 'id': '1da75b85900e00adb072e91c56fd9149'}, 'created_time': 1492318780, 'type': 'message', 'id': '6343862420'} > > > zhihu. Send_message (" 3 "hello, regards, user_id =" 1 da75b85900e00adb072e91c56fd9149 ") {' sender ': {'avatar_url_template': 'https://pic3.zhimg.com/ca6bf4bb82d9cf152b618edcbda01606_{size}.jpg', 'name': 'zhijun liu', 'is_advertiser': False, 'url': 'http://www.zhihu.com/api/v4/people/ba286d02fd9701a446d68ba85d0755c0', 'badge': [], 'user_type': 'people', 'url_token': 'zhijun-liu', 'Headline ':' Python zen ', 'avatar_url': 'https://pic3.zhimg.com/ca6bf4bb82d9cf152b618edcbda01606_is.jpg', 'is_org': False, 'gender': 1, 'type': 'people', 'id': 'ba286d02fd9701a446d68ba85d0755c0'} 'url' : ', 'has_read: False,' content ':' hello, greetings from 3 ', 'receiver' : {'avatar_url_template': 'https://pic1.zhimg.com/v2-ca13758626bd7367febde704c66249ec_{size}.jpg', 'name': : 'I am a small', 'is_advertiser' False, 'url' : 'http://www.zhihu.com/api/v4/people/1da75b85900e00adb072e91c56fd9149', 'badge' : [], 'user_type' : 'people' and 'url_token' : 'xiaoxiaodouzi', 'headline' : 'programmers',' avatar_url ': 'https://pic1.zhimg.com/v2-ca13758626bd7367febde704c66249ec_is.jpg', 'is_org': False, 'gender': -1, 'type': 'people', 'id': '1da75b85900e00adb072e91c56fd9149'}, 'created_time': 1492318799, 'type': 'message', 'id': '3244862420'} > > >Copy the code

TODO

  • Focus on
  • The article thumb up
  • .

contributors

Welcome PR, all contributors will be here

communication