知乎有 API 吗?用 Python 取问题和回答(2026)

有,知乎数据开放平台有搜索和问题回答,但搜索一次不超过 10 条、回答给的是摘要;要回答全文、评论和翻页搜索,用第三方数据接口。下面用 DataXAPI 的 Python SDK 演示,免费试用,最多 333 次。 用 2 个接口:知乎内容搜索 → 知乎问题回答。下面的示例一共 6 次调用,合计 $0.0120;失败的调用不收费。

更新于 2026-11-06在 ChatGPT 里打开在 Claude 里打开

按关键词搜回答,取赞同最多的 5 个回答所在问题的前 20 条回答全文,写进一张 CSV:问题、回答作者、赞同数、正文。

第 1 步:知乎内容搜索

按搜索词取一页回答和文章,type 选只要回答,sort 选最多赞同。回答的 parent_id 是它所在问题的编号。

curl -G "https://api.dataxapi.com/v1/zhihu/posts/search" \
  --data-urlencode "query=咖啡机推荐" \
  -H "Authorization: Bearer $DATAXAPI_API_KEY"
# pip install dataxapi
from dataxapi import DataXAPI

dx = DataXAPI()  # reads DATAXAPI_API_KEY
result = dx.zhihu.posts.search(query="咖啡机推荐")
print(result["data"]["items"])
// npm i @dataxapi/sdk
import { DataXAPI } from "@dataxapi/sdk";

const dx = new DataXAPI(); // reads DATAXAPI_API_KEY
const result = await dx.zhihu.posts.search({ query: "咖啡机推荐" });
console.log(result.data.items);
dataxapi call zhihu.posts.search 'query=咖啡机推荐'
录制的返回
{
  "code": "ok",
  "request_id": "87ee6f95-7dde-47c6-8b04-4ec1594169d0",
  "data": {
    "items": [
      {
        "id": "3250756632",
        "url": "https://www.zhihu.com/answer/3250756632",
        "type": "article",
        "title": "咖啡机推荐入门指南:一篇讲清楚",
        "text": "咖啡机推荐这件事,越简单越好",
        "published_at": "2026-03-03T08:11:12.000Z",
        "author": {
          "id": "cbf102a15e966bc955fc8f2b452b62fa",
          "username": "laozhou_gear",
          "name": "老周说装备",
          "avatar_url": "https://picx.zhimg.com/v2-671ebb705befb9d2492d_l.jpg",
          "followers": 10699
        },
        "metrics": { "likes": 224, "comments": 3, "favorites": 0 },
        "post_id": null,
        "parent_id": null
      },
      // … 另有 16 条
    ]
  },
  "page": {
    "next_cursor": "c1.Km3J8vP9d1xw85c8i-GQVxvJL7XKz0me6b3X34wR",
    "cursor_expires_at": "2026-10-12T20:18:45.000Z",
    "has_more": true,
    "returned": 17
  },
  "warnings": [],
  "meta": {
    "capability": "zhihu.posts.search",
    "result_status": "complete",
    "fetched_at": "2026-10-12T19:18:45.000Z",
    "cached": false,
    "replayed": false,
    "unavailable": {
      "lang": "capability",
      "author.verified": "capability",
      "metrics.shares": "platform",
      "metrics.views": "capability",
      "metrics.reposts": "platform",
      "images": "capability",
      "hashtags": "platform",
      "mentions": "capability",
      "is_pinned": "capability",
      "root_id": "platform"
    },
    "billing": {
      "amount": "0.002",
      "currency": "USD",
      "balance_after": "9.998"
    }
  }
}

取自 2026-10-12 19:18 UTC 录下的真实返回。名字、正文和编号是示例,链接也是,都不是录到的原文(页面不展示任何人的个人信息);数字是原样。长列表做了截断。请求号、游标和余额是示意。

知乎内容搜索 · $0.0020 / 一次 · 参数、字段和报错见接口页 →

第 2 步:知乎问题回答

把问题编号放进 id,取排在前面的 20 条回答,带正文、作者、赞同、评论和收藏数;不翻页。

curl -G "https://api.dataxapi.com/v1/zhihu/questions/answers/list" \
  --data-urlencode "id=55043447" \
  -H "Authorization: Bearer $DATAXAPI_API_KEY"
# pip install dataxapi
from dataxapi import DataXAPI

dx = DataXAPI()  # reads DATAXAPI_API_KEY
result = dx.zhihu.questions.answers.list(id="55043447")
print(result["data"]["items"])
// npm i @dataxapi/sdk
import { DataXAPI } from "@dataxapi/sdk";

const dx = new DataXAPI(); // reads DATAXAPI_API_KEY
const result = await dx.zhihu.questions.answers.list({ id: "55043447" });
console.log(result.data.items);
dataxapi call zhihu.questions.answers.list id=55043447
录制的返回
{
  "code": "ok",
  "request_id": "c2cb7ef3-9556-40a0-972e-f9fbc9adc683",
  "data": {
    "items": [
      {
        "id": "3612004169",
        "url": "https://www.zhihu.com/answer/3612004169",
        "type": "text",
        "title": "周末露营入门指南:一篇讲清楚",
        "text": "周末露营|第一次尝试就爱上了,清单放评论区",
        "published_at": "2017-01-23T02:28:14.000Z",
        "author": {
          "id": "f0065006fdb4498cad8c271c2752c668",
          "username": "aya_living",
          "name": "认真生活的阿雅",
          "avatar_url": "https://picx.zhimg.com/v2-514ec9961cf32ad9a5ba_l.jpg",
          "followers": 3641
        },
        "metrics": { "likes": 228, "comments": 34, "favorites": 698 },
        "post_id": "3675879886",
        "parent_id": "3901580217"
      },
      // … 另有 18 条
    ]
  },
  "page": {
    "next_cursor": null,
    "cursor_expires_at": null,
    "has_more": false,
    "returned": 19
  },
  "warnings": [
    { "code": "items_dropped", "count": 1 }
  ],
  "meta": {
    "capability": "zhihu.questions.answers.list",
    "result_status": "complete",
    "fetched_at": "2026-10-12T19:18:39.000Z",
    "cached": false,
    "replayed": false,
    "unavailable": {
      "lang": "capability",
      "author.verified": "capability",
      "metrics.shares": "platform",
      "metrics.views": "capability",
      "metrics.reposts": "platform",
      "images": "capability",
      "hashtags": "platform",
      "mentions": "capability",
      "is_pinned": "capability",
      "root_id": "platform"
    },
    "billing": {
      "amount": "0.002",
      "currency": "USD",
      "balance_after": "9.998"
    }
  }
}

取自 2026-10-12 19:18 UTC 录下的真实返回。名字、正文和编号是示例,链接也是,都不是录到的原文(页面不展示任何人的个人信息);数字是原样。长列表做了截断。请求号、游标和余额是示意。

知乎问题回答 · $0.0020 / 一次 · 参数、字段和报错见接口页 →

示例花多少钱

一页搜索结果,再取 5 个问题的回答

接口调用次数单价小计
知乎内容搜索1$0.0020$0.0020
知乎问题回答5$0.0020$0.0100
合计6$0.0120

价格是生成本页时的现行价格。失败的调用不收费。

在 AI 里做(MCP)

把 DataXAPI 接进你的 AI 客户端,只要接一次。之后直接说要什么,代理自己找到这些接口、看好价格,用你的余额调用。

这样说: 在知乎搜“咖啡机推荐”,找赞同最多的 5 个回答所在的问题,取每个问题前 20 条回答,总结大家推荐了哪些型号。
代理发给 call 工具的参数
{
  "capability": "zhihu.posts.search",
  "query": "咖啡机推荐",
  "idempotency_key": "<a new UUID>"
}

登录后复制带你 Key 的接入提示词了解 MCP 服务 →

为什么用 DataXAPI

  • 稳定:近 30 天接口可用 100%,状态页公开,可以自己核对。
  • 快:近 7 天付费调用的中位耗时 1.7 秒(2026-11-06 统计)。
  • 省 token:知乎的 16 个接口各取一份录制的真实返回,平台原始 JSON 合计 71.2 万 token,AI 通过 DataXAPI 的 MCP 读到的只有 6.3 万 token,少 91%;直接调接口拿到的 JSON 也少 73%(2026-11-06 统计)。所有平台同一种格式:作者在 author,互动数在 metrics,翻页用 page.next_cursor,换平台不用重写解析。
  • 先看再用:每个接口的页面上都有一份录制的真实返回,字段一目了然。
  • 花钱可控:失败不收费;每把 Key 能设金额上限,X-Max-Price 限定一次最多花多少,同一个 Idempotency-Key 24 小时内不重复扣费。
  • 接 AI 方便:远程 MCP 服务已在 MCP 官方登记处登记(com.dataxapi/mcp),Claude、Cursor、ChatGPT 都能直接用。
  • 免费试用,最多 333 次,不用绑卡。

要知道的

  • 赞同数在 metrics.likes。不用知乎账号和 Cookie,也不用处理 x-zse-96 签名。
  • 回答下的评论用 zhihu.answers.comments.list,按回答编号取。
  • 不写代码也行:把 DataXAPI 接进 Claude 或 ChatGPT,用下面“在 AI 里做”的那句话。

完整脚本

上面这件事写成一个能直接跑的脚本:Python,用 SDK,Key 从 DATAXAPI_API_KEY 读。它写出一个 CSV 文件,最后打印调了几次、取到几条、扣了多少。

Python
# pip install dataxapi
# export DATAXAPI_API_KEY=dx_...   (your key)
import csv
from decimal import Decimal
from dataxapi import DataXAPI

dx = DataXAPI()
calls, fetched, charged = 0, 0, Decimal("0")

def run(capability, params):
    """One call; counts it and what it was charged."""
    global calls, charged
    result = dx.call(capability, params)
    calls += 1
    charged += Decimal(str(result["meta"]["billing"]["amount"]))
    return result

QUERY = "咖啡机推荐"
QUESTIONS = 5

# 1. A page of answers for the search terms; parent_id is each answer's question.
answers = run("zhihu.posts.search", {"query": QUERY, "type": "answer"})["data"]["items"]
answers = sorted(answers, key=lambda each: -(each["metrics"].get("likes") or 0))
questions = list(dict.fromkeys(each["parent_id"] for each in answers if each.get("parent_id")))[:QUESTIONS]

# 2. The first 20 answers to each of those questions, in full.
rows = []
for question in questions:
    for answer in run("zhihu.questions.answers.list", {"id": question})["data"]["items"]:
        rows.append([answer.get("title"), answer["author"].get("name"), answer["metrics"].get("likes"), answer.get("text")])

fetched = len(rows)
with open("zhihu-answers.csv", "w", newline="", encoding="utf-8") as file:
    csv.writer(file).writerows([["question", "author", "upvotes", "text"], *rows])

print(f"calls: {calls}, items: {fetched}, charged: ${charged}")