zhihu
zhihu 是一个简单的知乎信息获取工具,可以免登陆实现获取知乎的用户(User),提问(Question),回答(Answer)信息
install
pip3 install zhihu-cli
Usage
用户类 User
可以通过用户的 自定义ID(customized_id) 或者 内部ID(internal_id) 初始化用户信息,其中 自定义ID 从用户URL中即可获得
例如 知乎小管家URL:https://www.zhihu.com/people/zhihuadmin/activities
自定义ID 即为 zhihuadmin
内部ID 是形如 3d198a56310c02c4a83efb9f4a4c027e 这样的ID,需要通过其他手段拿到。
而这两种ID均可以初始化User类
from zhihu import User
user = User('zhihuadmin')
而此时就可以通过 user.internal_id来获取到知乎小管家的 内部ID (就是上面的3d198a56310c02c4a83efb9f4a4c027e)
用户类的属性包括:
| 属性 | 类型 | 描述 |
|---|---|---|
| customized_id | str | 自定义ID |
| internal_id | str | 内部ID |
| nickname | str | 昵称 |
| gender | str | 昵称 |
| avatar | str | 头像URL |
| headline | str | 个人简介 |
| is_vip | bool | 盐选会员 |
| follower_count | int | 关注者数量 |
| following_count | int | 关注的人数量 |
| followers | generator 对象 | 关注者 |
| followings | generator 对象 | 关注的人 |
| answer_count | int | 回答数量 |
| question_count | int | 提问数量 |
| articles_count | int | 文章数量 |
| voteup_count | int | 获得赞同数 |
| info | dict | 以上所有信息 |
提问类 Question
通过 问题ID(qid) 初始化一个问题
问题ID 可以通过 问题URL 获得
例如:《如何使用知乎?》问题URL: https://www.zhihu.com/question/19550225
问题ID 即为 19550225
from zhihu import Question
question = Question('19550225')
问题类的属性包括:
| 属性 | 类型 | 描述 |
|---|---|---|
| qid | str | 问题ID |
| title | str | 标题 |
| detail | str | 详细描述 |
| type | str | 问题状态 |
| created | datetime | 发布时间 |
| updated | datetime | 最后一次更新时间 |
| author | User 对象 | 提问人 |
| info | dict | 以上所有信息 |
| answers() | generator 对象 | 所有回答的生成器 |
answers() 接受sort_by = default|updated 参数,返回类型为 Answer 对象
回答类 Answer
通过 回答ID(aid) 初始化一个回答
回答ID 可从一个回答的URL中获得:
例如:https://www.zhihu.com/question/19550225/answer/95067981
回答ID 即为 95067981
from zhihu import Answer
answer = Answer('95067981')
回答类的属性包括:
| 属性 | 类型 | 描述 |
|---|---|---|
| aid | str | 回答ID |
| type | str | 该回答状态 |
| author | User 对象 | 回答者 |
| excerpt | str | 摘要 |
| content | str | 回答的原始内容(包含HTML内容) |
| text | str | 回答的纯文字(不包含HTML内容) |
| comment_count | int | 回答评论数 |
| voteup_count | int | 回答赞同数 |
| created | datetime | 回答时间 |
| updated | datetime | 最后一次修改时间 |
| question | Question 对象 | 回答的问题对象 |
| info | dict | 以上所有信息 |
Metadata
Release files for zhihu-cli 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| zhihu-cli-1.2.0.tar.gz | 5.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| zhihu_cli-1.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.6 kB
Release files / zhihu-cli-1.2.0.tar.gz
| Download URL | zhihu-cli-1.2.0.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
976152c86ad8d9bbcd8152acd9ba5eec0ab234c679191a0b76df6eed2f27249b
|
|
BLAKE2b-256 checksum How to use checksums |
ceed2d856145b7d0d829987360c7c7a78326a2cdd67d61a1babf5568b11f7298
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
|
Release files / zhihu_cli-1.2.0-py3-none-any.whl
| Download URL | zhihu_cli-1.2.0-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c0b847044516ace4ac94b272f2af0bbc47d6c73f9b3bca461f7245e149ceb060
|
|
BLAKE2b-256 checksum How to use checksums |
7c526a6eefdc4289398005544370e62ef874685c959b7d933b34445fc3211b2f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
|
Security for zhihu-cli 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.