跳到导航

怎样导出视频号评论,整理观众反复问的问题?

用目标视频的数字 ID 调 wechat_channels.v2.fetch_video_comments 取可见评论,保存每次响应,再用 export_channel_comments.py 把已存响应导出成 comment-observations.csv。一级评论的 comment_id 留空。要读某条评论的回复,就填这条父评论的 comment_id,从父评论回复分支的第一页开始。

例如你做了一条活动介绍视频,想知道观众对门票、预约和入场有什么疑问。找出具体问题,核对视频是否已经回答每个问题,再决定往 FAQ 或视频介绍里补什么。

从一条视频开始,怎样做?

  1. 确认目标作品。 有数字作品 ID 就直接复用;只有分享链接时,按链接与标识流程先确认作品与发布账号。
  2. 读取一级评论。 先读最多 3 页,保存评论正文、实际返回的点赞数、时间及来源。研究需要更大范围时,另安排下一批。
  3. 展开会改变理解的回复。 例如“这个还要另外预约吗”可能指某个具体项目,读这条父评论的回复,并保留父评论与回复的关系。
  4. 整理问题。 评论者原句与你的归纳分列。先核对视频本身的说明,再写下一步:引用已有说明、补充说明,或核实细节。

可以给已连接 BeatAPI 的助手这样的任务:

读取这条活动视频最多3页评论,整理票价、预约和入场方面的问题。每个问题保留原句和来源;需要理解上下文时再看该条回复。导出评论材料表,并列出值得补进FAQ的问题。

评论怎样变成能用的FAQ线索?

实际看到什么如何记录后续处理
多条评论问同一预约步骤归到同一问题,保留各自原句对照视频说明,补清楚步骤或入口
“上次去不用预约”这类经历标为评论者自述,记录经历的时间核对本次活动规则后再引用
回复补充“儿童也要单独预约”和父评论一起保存查证规则,决定是否补充说明
简短表情、赞美或无关内容留在材料表,在问题整理中排除不强行解释成需求

措辞相近的评论可以归为同一主题,但同一条评论重复返回仍只是一条来源。按实际核对过的问题记录来描述结果;3 页评论样本不代表所有观众。

拿到导出文件后先看什么?

comment-observations.csv 每行一条评论观察,coverage.json 记录作品、父评论分支、实际读取的页数与停止原因。先读评论正文选问题,再从原始响应里选择需要展开的父评论。本页后面的 prepare_reply_branch.py 直接从已存响应生成回复分支请求,避免从表格复制被软件改写过的长 ID。

comment-observations.csv 不含昵称、头像和属地资料列,整理时只看问题。分享前检查评论正文里有没有评论者自己透露的个人信息;原始响应与内部研究表分开保存。

下面几节讲取评论、保存页面与本地导出。export_channel_comments.py 每次运行只处理一条作品的一个分支。

选一级评论分支或一个回复分支

两种分支都用 data:wechat_channels.v2.fetch_video_comments:

  • 一级评论设 comment_id=""。
  • 回复设为选定父评论的原始 comment_id。

一级分支和回复分支是同一个动作的不同范围,不是另一个回复接口。每个分支开始时把 last_buffer 重置为 "",并明确设置 raw:false。响应包含 data.object_id、comment_id、comments、down_continue 和 last_buffer;每条评论有 comment_id 和 content,可选 like_count、reply_count 和 create_time。reply_count 是回复数,不等于已经取到回复。

一级评论请求如下,按你的目标替换作品 ID。发送请求需要单独批准;后面的导出器离线处理已保存响应:

{"action":"wechat_channels.v2.fetch_video_comments","params":{"object_id":"14941130915890399732","comment_id":"","last_buffer":"","raw":false}}

保存完整响应,每次导出一个分支

  1. 创建 comment-pages.json,其中的路径相对于清单文件。后续每一页都用上一页实际返回的 last_buffer,不是页码;object_id、comment_id、raw 保持不变。记录每页真实的 HTTP 状态与采集时间,包括末页失败响应。传输超时没有响应时,不要伪造 JSON。
[{"action":"wechat_channels.v2.fetch_video_comments","params":{"object_id":"14941130915890399732","comment_id":"","last_buffer":"","raw":false},"http_status":200,"collected_at":"2026-11-17T09:00:00Z","response_file":"root-1.json"}]
  1. 把下面的脚本保存为 export_channel_comments.py,运行 python3 export_channel_comments.py comment-pages.json root-review。
  2. 选定父评论的回复另用一份清单和一个输出目录,例如 reply-123-review。不要把一级页与回复页拼成同一条分页链。

export_channel_comments.py 核对返回的 object_id 和父评论身份;返回的回显不安全或不一致时,export_channel_comments.py 在创建输出前停止,不信任可能已被舍入的标识。

import csv,hashlib,json,pathlib,re,sys
from datetime import datetime
manifest,out=map(pathlib.Path,sys.argv[1:3]);original=manifest.read_bytes();pages=json.loads(original)
if not isinstance(pages,list) or not 1<=len(pages)<=3:raise ValueError('Supply 1–3 saved pages for one branch')
ACTION='wechat_channels.v2.fetch_video_comments';rows,sources,ids,rids,cursors=[],[],set(),set(),set();expected='';account=None;parent=None;stop=None;unsafe=0
def cell(v):
if v is None:return ''
v=str(v);return "'"+v if v.startswith(('=','+','-','@','\t','\r','\n')) else v
def identity(v):
if isinstance(v,str) and re.fullmatch(r'[0-9]{1,32}',v):return v,'string'
if type(v) is int and 0<=v<=9007199254740991:return str(v),'safe_integer'
return None,'unsafe_or_invalid'
for i,e in enumerate(pages,1):
if stop is not None:raise ValueError('Pages supplied after stop condition')
params=e.get('params');u=params.get('object_id') if isinstance(params,dict) else None
if e.get('action')!=ACTION or not isinstance(params,dict) or set(params)!={'object_id','comment_id','raw','last_buffer'} or params['raw'] is not False:raise ValueError('Use exact raw:false list request')
if not isinstance(u,str) or not re.fullmatch(r'[0-9]{1,32}',u):raise ValueError('Invalid object ID string')
branch=params['comment_id']
if not isinstance(branch,str) or not re.fullmatch(r'[0-9]{0,32}',branch):raise ValueError('Invalid parent ID string')
if account is None:account,parent=u,branch
if u!=account or branch!=parent or params['last_buffer']!=expected:raise ValueError('Account or cursor chain changed')
cursors.add(expected)
t=e.get('collected_at')
if not isinstance(t,str) or datetime.fromisoformat(t.replace('Z','+00:00')).tzinfo is None:raise ValueError('Record actual collection time with timezone')
http=e.get('http_status')
if type(http) is not int or not 100<=http<=599:raise ValueError('Invalid HTTP status')
raw=(manifest.parent/e['response_file']).read_bytes();body=json.loads(raw)
if not isinstance(body,dict):raise ValueError('Expected response object')
source={'index':i,'request':e,'sha256':hashlib.sha256(raw).hexdigest(),'raw_file':'raw-%02d.json'%i};sources.append((source,raw))
if http!=200:
error=body.get('error')
if not isinstance(error,dict) or not isinstance(error.get('code'),str) or not error['code'].strip():raise ValueError('Expected gateway error')
source.update(error_code=error['code'],request_id=error.get('request_id'));stop='gateway_failed';continue
data=body.get('data');rid=body.get('request_id')
if body.get('status')!='succeeded' or body.get('action')!=ACTION or body.get('error') is not None or not isinstance(data,dict):raise ValueError('Wrong successful envelope')
if not isinstance(rid,str) or not rid.strip() or rid in rids:raise ValueError('Missing or duplicate request ID')
rids.add(rid);source['request_id']=rid
echo,_=identity(data.get('object_id'));parent_echo,_=identity(data.get('comment_id'))
if echo!=account or (parent and parent_echo!=parent) or (not parent and data.get('comment_id') not in (None,'')) or not isinstance(data.get('comments'),list):raise ValueError('Missing, unsafe or mismatched object/parent echo or comments array')
videos=data['comments'];source['reported_count']=data.get('count');source['observations']=len(videos)
for j,v in enumerate(videos):
if not isinstance(v,dict):raise ValueError('Invalid comment object')
object_id,state=identity(v.get('comment_id'));duplicate=object_id in ids if object_id is not None else False
if object_id is None:unsafe+=1
else:ids.add(object_id)
row={'object_id':account,'parent_id':parent,'comment_id':object_id,'id_state':state,'id_raw':json.dumps(v.get('comment_id')),'duplicate_observation':str(duplicate).lower(),'content':v.get('content'),'content_present':str('content' in v).lower(),'collected_at':t,'request_id':rid,'source_index':i,'comment_index':j}
if row['content'] is not None and not isinstance(row['content'],str):raise ValueError('Invalid comment text')
for field in ['create_time','like_count','reply_count']:
row[field+'_raw']=json.dumps(v.get(field),ensure_ascii=False);row[field+'_present']=str(field in v).lower()
rows.append(row)
flag=data.get('down_continue');cursor=data.get('last_buffer');source.update(down_continue=flag,last_buffer=cursor)
if type(flag) not in (bool,int) or flag not in (0,1):stop='unsupported_more_flag'
elif not flag:stop='provider_end'
elif not videos:stop='empty_page_with_more'
elif not isinstance(cursor,str) or not cursor or not re.fullmatch(r'[A-Za-z0-9+/=_-]+',cursor):stop='missing_or_invalid_cursor'
elif cursor in cursors:stop='repeated_cursor'
else:expected=cursor
if stop is None:stop='saved_page_limit'
columns=['object_id','parent_id','comment_id','id_state','id_raw','duplicate_observation','content','content_present','collected_at','request_id','source_index','comment_index']
for field in ['create_time','like_count','reply_count']:columns.extend([field+'_raw',field+'_present'])
out.mkdir(mode=0o700,exist_ok=False)
with (out/'comment-observations.csv').open('x',encoding='utf-8-sig',newline='') as f:
w=csv.DictWriter(f,fieldnames=columns);w.writeheader();w.writerows({k:cell(v) for k,v in r.items()} for r in rows)
for source,raw in sources:(out/source['raw_file']).write_bytes(raw)
(out/'manifest.json').write_bytes(original)
report={'object_id':account,'parent_id':parent,'sources':[s for s,_ in sources],'stop_reason':stop,'comment_observations':len(rows),'distinct_usable_ids':len(ids),'unsafe_id_observations':unsafe,'provider_end_seen':stop=='provider_end','all_comments_verified':False,'author_profile_fields_exported':False,'executed_calls':0,'manifest_sha256':hashlib.sha256(original).hexdigest()}
(out/'coverage.json').write_text(json.dumps(report,ensure_ascii=False,indent=2),encoding='utf-8')
if stop=='saved_page_limit':(out/'unexecuted-next-request.json').write_text(json.dumps({'action':ACTION,'params':{'object_id':account,'comment_id':parent,'raw':False,'last_buffer':expected}},indent=2),encoding='utf-8')
print(json.dumps({'observations':len(rows),'stop_reason':stop,'executed_calls':0}))

验收表格,而不只是HTTP成功

  • CSV 每行是一条观察。export_channel_comments.py 会标记重复的可用评论 ID,不静默覆盖前一行;缺失和 null 计数分开保留。同一评论重复出现不等于第二条独立意见。
  • 评论 ID 不安全的行没有可用的 comment_id。这一行的正文仍可凭 source_index 和 comment_index 审阅,但不能安全地用来请求回复;不要把舍入后的数字转成文字假装修复。
  • provider_end 只表示当前分支到达服务端报告的终点。一级分支结束不代表任何回复分支结束。预算用完、游标重复或缺失、空页仍报告有更多、未知标记是各自独立的停止原因。
  • 末页网关错误时,保留前面各页的评论和错误证据;作品或父评论混用、结构错误或游标链断开时,整批拒绝。export_channel_comments.py 不覆盖已有输出;写入中断的输出目录按未完成处理。
  • CSV 刻意不带昵称、username、头像与 IP 属地字段。评论正文仍可能暴露身份,删掉资料列不等于匿名化。分享时另做审核脱敏的副本,原件只存在私有本地证据目录。脚本不上传、不发通知。

先限定审核预算

例如先取 3 页一级评论,再为选中的 2 个父评论各取 1 页回复,计划最多 5 次评论页请求。按价格页当前单价估算这 5 次请求;定位作品和额外页面是另外的请求,实际评论条数取决于响应。在本地导出和阅读已存材料不需要新的取数请求。

读导出的正文,选出少量值得核对的问题或投诉,每条引用旁保留来源行。有限样本不能支撑关于整体情感、代表性、独立用户数或全部公开讨论的结论。选中的回复分支可以补充上下文,但保存的回复请求必须对应一级证据里那个确切且安全的父评论。

导出前用已保存的响应核对评论字段和游标字段。本页示例中的记录是合成数据。

从一级原件选择父评论,而不是复制表格里被编辑的ID

  1. 在一级导出表里选父评论的 source_index(从 1 开始的页号)和 comment_index(原 comments 数组里从 0 开始的行号)。
  2. 把下面的脚本保存为 prepare_reply_branch.py,运行 python3 prepare_reply_branch.py root-review 1 0 selected-parent。运行前先人工阅读那条确切的原评论;不要按标题、作者名或最大 reply_count 自动选父评论。
  3. prepare_reply_branch.py 重新读取归档响应,核对响应的哈希、动作、一级范围与身份,不信任 CSV 里被编辑过的评论 ID:安全整数或原始数字字符串可用,不安全的裸数字父 ID 会在创建输出前停止。reply_count 不作为回复当前可取的证明。
  4. prepare_reply_branch.py 把未执行的回复请求和本地父评论来源证据写进新目录 selected-parent。
import hashlib,json,pathlib,re,sys
root=pathlib.Path(sys.argv[1]);source_index=int(sys.argv[2]);comment_index=int(sys.argv[3]);out=pathlib.Path(sys.argv[4])
report_bytes=(root/'coverage.json').read_bytes();report=json.loads(report_bytes)
if report.get('parent_id')!='' or not isinstance(report.get('sources'),list):raise ValueError('Choose a root-comment export, not an existing reply branch')
obj=report.get('object_id')
if not isinstance(obj,str) or not re.fullmatch(r'[0-9]{1,32}',obj):raise ValueError('Invalid recorded object ID')
if not 1<=source_index<=len(report['sources']) or comment_index<0:raise ValueError('Choose the exact source_index and zero-based comment_index')
source=report['sources'][source_index-1];request=source.get('request');params=request.get('params') if isinstance(request,dict) else None
if source.get('index')!=source_index or not isinstance(params,dict) or request.get('action')!='wechat_channels.v2.fetch_video_comments' or params.get('object_id')!=obj or params.get('comment_id')!='' or params.get('raw') is not False or request.get('http_status')!=200:raise ValueError('Selected source is not a successful root request')
raw=(root/('raw-%02d.json'%source_index)).read_bytes()
if source.get('sha256')!=hashlib.sha256(raw).hexdigest():raise ValueError('Root raw source changed')
body=json.loads(raw);data=body.get('data')
if body.get('status')!='succeeded' or body.get('action')!=request['action'] or body.get('error') is not None or body.get('request_id')!=source.get('request_id') or not isinstance(body.get('request_id'),str) or not body['request_id'].strip() or not isinstance(data,dict):raise ValueError('Invalid root response')
def identifier(value):
if isinstance(value,str) and re.fullmatch(r'[0-9]{1,32}',value):return value
if type(value) is int and 0<=value<=9007199254740991:return str(value)
raise ValueError('Unsafe or missing identifier; do not stringify rounded IDs')
if identifier(data.get('object_id'))!=obj or data.get('comment_id') not in (None,''):raise ValueError('Root identity mismatch')
comments=data.get('comments')
if not isinstance(comments,list) or comment_index>=len(comments) or not isinstance(comments[comment_index],dict):raise ValueError('Comment source position missing')
parent=identifier(comments[comment_index].get('comment_id'))
request={'action':'wechat_channels.v2.fetch_video_comments','params':{'object_id':obj,'comment_id':parent,'last_buffer':'','raw':False}}
out.mkdir(mode=0o700,exist_ok=False)
(out/'unexecuted-reply-request.json').write_text(json.dumps(request,indent=2),encoding='utf-8')
(out/'parent-evidence.json').write_text(json.dumps({'object_id':obj,'parent_id':parent,'root_request_id':body['request_id'],'source_index':source_index,'comment_index':comment_index,'raw_sha256':hashlib.sha256(raw).hexdigest(),'coverage_sha256':hashlib.sha256(report_bytes).hexdigest(),'executed_calls':0,'root_export_path':str(root),'identity_basis':'selected stored root observation; not live availability or legal identity'},indent=2),encoding='utf-8')
print(json.dumps({'parent_id':parent,'executed_calls':0}))

单独批准采集后,在新的回复清单里记录这个确切的 object_id 和 comment_id、实际响应与时间,从 last_buffer="" 开始。用 export_channel_comments.py 写到独立的回复目录,并把 selected-parent 目录放在回复目录旁边。selected-parent 让回复分支的选择能追溯到已记录的一级页面,但不表示回复页已经取回。一级证据的哈希只证明本地字节一致,不认证网络来源;不要同时修改原件和元数据来绕过校验。两个脚本都不会自动调用、重试或展开分支。