> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.beatapi.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.beatapi.io/_mcp/server.

# 用Python搜微博、读选中讨论的评论，整理产品使用问题

> 标准库保存一页搜索与选中微博的评论，人工核对对象和字段，再整理带原句、使用条件与下一步的问题清单。

用下面的 `weibo_read.py` 脚本，先以 `weibo.web_v2.fetch_realtime_search` 保存一页微博关键词搜索，再挑出真正谈到产品使用的微博，用各自的微博 ID 以 `weibo.web_v2.fetch_post_comments` 查评论。已有核对过的微博 ID 时，直接查评论。交给同事的表里保留问题、原句、使用条件和原微博。

例如研究露营灯，先搜「露营灯 低温续航」，再从实际使用的微博和评论里找温度、亮度档位和续航的疑问。`weibo_read.py` 只用 Python 3 标准库，每次运行保存一条请求及其完整响应。

## 1. 准备这一轮的范围

在本地环境配置 `BEATAPI_API_KEY`。`weibo_read.py` 从环境变量读取密钥，保存的文件不含鉴权头。先安排一页搜索，人工选 2–3 条相关微博，每条读一页评论。

1 页搜索加 3 页评论是 4 次数据查询，按[价格页](https://beatapi.io/zh/pricing)各动作的当前单价计算。只有微博需要全文时才查详情。请求的 `count` 不是实际返回的评论数。

## 2. 用Python保存一份原响应

把下方脚本保存为 `weibo_read.py`。`search` 模式调用 `weibo.web_v2.fetch_realtime_search`，`comments` 模式调用 `weibo.web_v2.fetch_post_comments`。每次运行用新的输出目录。

```python
import json
import os
import sys
from datetime import datetime, timezone
from pathlib import Path
from urllib.error import HTTPError, URLError
from urllib.request import Request, urlopen

if len(sys.argv) != 4 or sys.argv[1] not in {"search", "comments"}:
    raise SystemExit("Usage: python3 weibo_read.py search|comments VALUE NEW_DIRECTORY")
mode, value, directory = sys.argv[1:]
if not value.strip():
    raise SystemExit("Supply a query or a verified post ID")
key = os.environ.get("BEATAPI_API_KEY")
if not key:
    raise SystemExit("Set BEATAPI_API_KEY in your local environment")
if mode == "search":
    action = "weibo.web_v2.fetch_realtime_search"
    params = {"query": value, "page": 1}
else:
    action = "weibo.web_v2.fetch_post_comments"
    params = {"id": value, "count": 10, "max_id": ""}
body = {"action": action, "params": params}
out = Path(directory)
out.mkdir(parents=True, exist_ok=False)
(out / "request.json").write_text(json.dumps(body, ensure_ascii=False, indent=2), encoding="utf-8")
started = datetime.now(timezone.utc).isoformat()
(out / "attempt.json").write_text(json.dumps({"started_at": started, "action": action}), encoding="utf-8")
request = Request("https://api.beatapi.io/v1/social-data/call",
                  data=json.dumps(body).encode("utf-8"), method="POST",
                  headers={"Authorization": "Bearer " + key, "Content-Type": "application/json"})
try:
    with urlopen(request, timeout=60) as response:
        status, raw = response.status, response.read()
except HTTPError as error:
    status, raw = error.code, error.read()
except URLError:
    (out / "transport-error.json").write_text(json.dumps({"outcome": "unknown", "action": action}), encoding="utf-8")
    raise SystemExit("No final response saved; review the attempted request before repeating")
(out / "response.json").write_bytes(raw)
(out / "call.json").write_text(json.dumps({"action": action, "params": params,
    "http_status": status, "started_at": started,
    "finished_at": datetime.now(timezone.utc).isoformat(),
    "response_file": "response.json", "platform_review": "required"},
    ensure_ascii=False, indent=2), encoding="utf-8")
try:
    payload = json.loads(raw)
except (ValueError, UnicodeError):
    raise SystemExit("Saved a non-JSON response; inspect response.json")
if status != 200 or not isinstance(payload, dict) or payload.get("status") != "succeeded" or payload.get("error") is not None or payload.get("action") != action:
    raise SystemExit("Saved a failed or unexpected response; inspect response.json")
print("Saved response for platform-content review: " + str(out / "response.json"))
```

取一页搜索：

```bash
python3 weibo_read.py search '露营灯' weibo-search-01
```

每个输出目录保存请求、尝试时间、调用记录（`call.json`）和原响应（`response.json`）。`weibo_read.py` 只检查公共执行信封；微博内容仍要人工阅读，`call.json` 里记为 `platform_review: required`。脚本保存所有 HTTP 返回；网络中断时，脚本记录这次尝试后退出，从不自动重试，也不覆盖已有目录。

## 3. 先选真正相关的微博

1. **核对每条结果。** 读搜索返回的实际微博，核对产品、场景和作者。
2. **优先选有用的微博。** 优先选有使用经历、具体疑问或值得展开讨论的微博。
3. **排除干扰。** 无关同名内容和活动转发排除，并记下每条的排除原因。

已确认的微博 ID 按原始字符串保存，同时记录来源、选择理由、原文和实际返回的时间信息。`weibo.web_v2.fetch_realtime_search` 和 `weibo.web_v2.fetch_post_comments` 尚未登记固定列表键，不要套用别家的 `data.items`、`metrics.comments` 或 `page.next_cursor`。先把材料保存好，再按实际结果确定微博。

选文可以用这样一张人工表：

| 对象         | 为什么选    | 本次想从评论里了解什么    |
| ---------- | ------- | -------------- |
| 已核对的户外使用微博 | 有明确夜间环境 | 亮度档位、持续时间与使用条件 |
| 已核对的配件讨论   | 有具体充电问题 | 电源、接口与兼容条件     |
| 无关活动转发     | 不涉及使用   | 排除，保留原因        |

长文正文不完整时，按[正文与编号说明](/zh/faq/weibo-identifiers)补取选中微博的详情，不用摘录代替全文。

## 4. 读取选中微博的评论

用已确认的微博 ID 和新目录运行 `comments` 模式：

```bash
python3 weibo_read.py comments '<confirmed_post_id>' weibo-comments-01
```

每条选中微博的评论分别存进单独的目录。`weibo.web_v2.fetch_post_comments` 的 `id` 是微博 ID，首个 `max_id` 为空；下一页用响应实际返回的续页值。`weibo_read.py` 只取首批评论，不会自动选帖、翻页或读全部回复。

遇到“能撑多久”“你说的不是这款”等含糊评论，按[评论研究问答](/zh/faq/weibo-comment-research)补父子上下文。读回复时传的是一级评论 ID，不是微博 ID。

## 5. 从原材料整理成团队能处理的问题

人工工作表保留：主题、支持原句、微博与评论来源、父子关系、使用条件、判断理由、待核项和下一步。支持评论数和不同微博数分开统计，同一段讨论里的多条回复保留关系。

例如，把“低温高亮能撑多久”交给测试与说明核对；确有型号纠正的讨论先分组再判断；抽奖参与留言不进入使用主题。每个结论都要能回到保存的材料，不从关键词自动推断用户态度。

这条流程交付搜索与评论的原响应，以及人工审阅过的问题表。按评论数自动选前 10、按统一字段自动导出 CSV，都需要先确认输出结构，所以本指南不提供基于猜测字段的批量解析器。

给已接入 BeatAPI 工具的助手，可以这样布置：

> 复用这轮Python保存的搜索和评论，选与露营灯实际使用有关的内容。每个问题附原句、条件和来源，必要时指出要补哪段回复。列出可写进说明的内容与待测试事项，说明实际读过的范围。

先处理已有问题，再按缺口安排下一轮读取。定时运行、存储和通知在自己的任务环境里配置。

[搜索与选文](/zh/faq/weibo-keyword-search) · [评论到问题清单](/zh/faq/weibo-comment-research)