mikecoding / 知乎回答评论导出

Published:

Version: 1.0.0+c195b40

Summary: 导出知乎回答内容、评论及子评论为 JSON/Markdown

Copyright: 2026, mikecoding (https://openuserjs.org/users/mikecoding)

License: MIT

Antifeature: unspecified

知乎回答·评论导出

一个 Tampermonkey 油猴脚本,一键导出知乎问题下的回答内容所有评论评论的评论(子评论),支持 JSON 和 Markdown 两种格式。

功能

  • 📝 回答内容 — 自动展开「阅读全文」,提取完整回答正文
  • 💬 全部评论 — 逐页拉取所有根评论(支持分页)
  • 🔁 子评论 — 提取每条评论下的回复(支持分页)
  • 📄 双格式导出 — JSON(完整结构化数据)/ Markdown(方便阅读)
  • 🧩 可折叠面板 — 右下角浮动面板,点击标题栏可收起,不遮挡内容
  • 🔄 SPA 兼容 — 知乎是 React 单页应用,页面切换后自动重新挂载按钮

安装

  1. 安装 Tampermonkey 浏览器扩展
  2. Install 本脚本
  3. 打开任意知乎问题页面,右下角会出现导出面板

使用

打开知乎问题页面(如 zhihu.com/question/123456)或具体回答页面(如 zhihu.com/question/123456/answer/789012):

  • 点击 📥 导出 JSON → 下载完整结构化数据
  • 点击 📝 导出 Markdown → 下载格式化可读文档
  • 点击标题栏 📋 知乎回答·评论导出 → 折叠/展开面板

导出内容

JSON 结构

{
  "exportedAt": "2026-06-17T...",
  "url": "https://www.zhihu.com/question/...",
  "questionTitle": "问题标题",
  "answers": [
    {
      "author": { "name": "作者名", "headline": "作者简介" },
      "content": "<p>回答 HTML</p>",
      "contentText": "回答纯文本",
      "voteupCount": 937,
      "commentCount": 107,
      "totalRootComments": 107,
      "totalChildComments": 45,
      "comments": [
        {
          "id": "11202932515",
          "content": "评论内容",
          "author": { "name": "评论者", "isAuthor": false },
          "createdTime": 1749844557,
          "likeCount": 54,
          "location": "湖南",
          "childCommentCount": 9,
          "childComments": [
            {
              "content": "子评论内容",
              "author": { "name": "回复者", "isAuthor": true },
              ...
            }
          ]
        }
      ]
    }
  ]
}

Markdown 预览

# 问题标题

## 作者名
*作者简介*

👍 937 赞同 | 💬 107 评论 | 45 子评论

### 📝 回答内容
回答正文...

### 💬 评论 (107 条)

**评论者A**
> 评论内容
> 👍54 📍湖南 · 2025/6/14 10:00:00

  **评论者B** 🅰️
  > 回复内容
  > 👍6 · 2025/6/14 14:00:00

技术原理

数据来源

数据 来源 说明
回答内容 页面 SSR 数据 + DOM 优先取 DOM 中展开后的完整内容
根评论 /api/v4/comment_v5/answers/{id}/root_comment 无需登录,自动分页
子评论 根评论 API 响应中的 child_comments[] 已包含,支持 child_comment_offset 分页

评论 API

GET /api/v4/comment_v5/answers/{answer_id}/root_comment
    ?order_by=score
    &limit=20
    &offset=

Response:
{
  "counts": { "total_counts": 107 },
  "data": [{
    "id": "...",
    "content": "...",
    "author": { "name": "...", "url_token": "..." },
    "like_count": 54,
    "child_comment_count": 9,
    "child_comments": [ ... ],
    "child_comment_next_offset": "..."
  }],
  "paging": { "is_end": false, "next": "https://..." }
}

配置

脚本顶部的 CONFIG 对象可调整:

const CONFIG = {
  commentPageSize: 20,      // 每页评论数
  maxRootComments: 0,       // 最大根评论数(0=不限)
  maxChildComments: 0,      // 最大子评论数(0=不限)
  requestDelay: 300,        // API 请求间隔(ms)
  expandRetryCount: 10,     // 展开内容重试次数
  expandRetryDelay: 500,    // 展开内容重试间隔(ms)
};

兼容性

  • ✅ 单回答页 /question/{id}/answer/{answerId}
  • ✅ 问题列表页 /question/{id}(导出页面上所有可见回答)
  • ✅ 滚动加载的回答(自动识别 DOM 中新增的 .AnswerItem
  • ✅ 未登录状态(评论 API 无需登录)

License

MIT

Rating: 0