zhihuAPI Documentation

Introduction

zhihuAPI provides a python implementation of APIs from https://www.zhihu.com .

The aim of this project is to make a large collection of APIs, instead of building a smart crawler. Therefore APIs are called in a general framework and only minimal working interface is available. You can add your own wrappers for specific functionalities and implement strategies for large scale crawling, but they are out of the scope of this package.

Authorization

Unfortunately an automated login is not implemented (login with username and password). This is because Zhihu frequently changes their login code, and makes the required request values increasingly difficult to generate. If there is a stable and relatively easy way to simulate login, please inform me.

To make API calls, you need a working Zhihu account. Currently zhihuAPI reads from an exported json file for cookies. The required file format is:

[
   {
      "domain":".zhihu.com",
      "name":"zap",
      "value":"xxxxx",
      ...
   },
   ...
]

One way to obtain this file is to use the “cookie inspector” extension for Chrome, when you visit Zhihu, open the developer tools, cookies tab (usually the last one), right click and export all cookies. Afterwards, the instance can be created with:

from zhihuAPI.account import ZhihuAccount
machine = ZhihuAccount('path/to/cookie.json')