Skip to content

Pluviobyte/saas-growth-agents / bots/social-kb/douyin-comments

douyin-comments

Verified

抓取抖音单条视频的完整评论区(一级评论 + 全部楼中楼回复)和视频详情,可选下载视频,输出按点赞排序的「评论全文.md」和原始 JSON。在已登录抖音的真实浏览器里运行(Claude in Chrome,或 Grok Bot 等 Agent 自带、能执行页面脚本的浏览器),借页面自带 SDK 签名,不需要 TikHub、Playwright 或 a_bogus 逆向。用户给出抖音视频链接(douyin.com/video/…、带 modal_id 的主页链接、v.douyin.com 短链),并说"看评论区""抓评论""拉评论""评论区有什么质疑/疑问""参考评论区"时使用。只适用于抖音单条视频;小红书、B 站、批量采集博主全部作品不适用。

FileKindSize
SKILL.mdskill md9.4 KB
scripts/build_report.pyscript3.6 KB
scripts/download_video.pyscript1.1 KB
scripts/page_fetch.jsscript4.3 KB
scripts/page_hook.jsscript2.1 KB
scripts/page_ui_expand.jsscript1.8 KB
scripts/recv.pyscript1.6 KB

scripts/build_report.py

View on GitHub
#!/usr/bin/env python3
"""合并 raw/ 里主路线与兜底路线抓到的所有分页,按 cid 去重,做完整性校验,输出评论全文。

用法:python3 -I build_report.py <输出目录>        # raw 文件在 <输出目录>/raw/
输出:comments_top.json · comments_replies.json · 评论全文.md;完整性结果打印到 stdout
退出码:0 = 全部抓齐;2 = 有楼没抓全(会列出 cid,可用兜底路线补抓后重跑)
"""
import glob
import json
import os
import sys
import time

out = sys.argv[1]
raw = os.path.join(out, "raw")


def load(path):
    try:
        with open(path) as f:
            return json.load(f)
    except Exception:
        return None


top, replies = {}, {}
for path in sorted(glob.glob(os.path.join(raw, "top_*.json")) + glob.glob(os.path.join(raw, "ui_top_*.json"))):
    for c in (load(path) or {}).get("comments") or []:
        top[c["cid"]] = c
for path in sorted(glob.glob(os.path.join(raw, "reply_*.json")) + glob.glob(os.path.join(raw, "ui_reply_*.json"))):
    for r in (load(path) or {}).get("comments") or []:
        replies[r["cid"]] = r

detail = (load(os.path.join(raw, "detail.json")) or {}).get("aweme_detail") or {}
stats = detail.get("statistics") or {}

by_parent = {}
for r in replies.values():
    by_parent.setdefault(r.get("reply_id"), []).append(r)

missing = []
for c in top.values():
    want = c.get("reply_comment_total") or 0
    got = len(by_parent.get(c["cid"], []))
    if got < want:
        missing.append((c["cid"], want, got, (c.get("text") or "")[:30]))


def body(c):
    t = (c.get("text") or "").replace("\n", " / ")
    if c.get("image_list"):
        t += "(附图)"
    if c.get("sticker"):
        t += "(表情包)"
    return t or "(空)"


def meta(c):
    when = time.strftime("%Y-%m-%d", time.localtime(c.get("create_time") or 0))
    return f"赞{c.get('digg_count', 0)}·{c.get('ip_label', '')}·{when}"


with open(os.path.join(out, "comments_top.json"), "w") as f:
    json.dump(list(top.values()), f, ensure_ascii=False)
with open(os.path.join(out, "comments_replies.json"), "w") as f:
    json.dump(list(replies.values()), f, ensure_ascii=False)

with open(os.path.join(out, "评论全文.md"), "w") as f:
    f.write(f"# 评论全文:{(detail.get('desc') or '').splitlines()[0][:40] if detail.get('desc') else detail.get('aweme_id', '')}\n\n")
    if detail:
        a = detail.get("author") or {}
        f.write(f"- 作者:{a.get('nickname', '')} | 发布:{time.strftime('%Y-%m-%d', time.localtime(detail.get('create_time') or 0))} | 时长:{(detail.get('duration') or 0) // 1000}s\n")
        f.write(f"- 赞 {stats.get('digg_count')} | 收藏 {stats.get('collect_count')} | 转发 {stats.get('share_count')} | 评论 {stats.get('comment_count')}\n")
    f.write(f"- 抓取:{time.strftime('%Y-%m-%d %H:%M')} | 一级 {len(top)} 条 + 回复 {len(replies)} 条\n\n")
    for c in sorted(top.values(), key=lambda c: -(c.get("digg_count") or 0)):
        f.write(f"- **[{meta(c)}] {c['user']['nickname']}**:{body(c)}\n")
        for r in sorted(by_parent.get(c["cid"], []), key=lambda r: r.get("create_time") or 0):
            to = r.get("reply_to_username") or ""
            f.write(f"  - [{meta(r)}] {r['user']['nickname']}{' → ' + to if to else ''}:{body(r)}\n")

total = len(top) + len(replies)
print(f"一级 {len(top)} | 回复 {len(replies)} | 合计 {total} | 视频显示评论数 {stats.get('comment_count', '未知')}")
if missing:
    print(f"未抓全的楼 {len(missing)} 个:")
    for cid, want, got, text in missing:
        print(f"  {cid} 应有 {want} 实得 {got} | {text}")
    sys.exit(2)
print("所有楼中楼已抓齐")
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall