# 微博有 API 吗？用 Python 搜微博、取评论（2026）

微博开放平台的读取接口围绕授权用户，评论接口只返回授权用户的评论，未审核应用只能授权 15 个测试账号；要用程序搜公开微博、读评论，用第三方数据接口。下面用 DataXAPI 的 Python SDK 演示，免费试用，最多 333 次。 用 2 个接口：微博实时搜索 → 微博评论。下面的示例一共 12 次调用，合计 $0.0240；失败的调用不收费。

更新于 2026-11-06

按关键词搜两页微博，取评论最多的 10 条的评论，写进一张 CSV：微博正文、转发和评论数、评论正文、评论点赞数。

## 一步一步做

### 第 1 步：微博实时搜索

按搜索词取一页微博，新发的在前；`metrics.comments` 是评论数，`id` 是微博编号。长微博在这里是截短的。（[微博实时搜索](https://dataxapi.com/zh/apis/weibo/posts/search/)，$0.0020 / 一次）

cURL

```bash
curl -G "https://api.dataxapi.com/v1/weibo/posts/search" \
  --data-urlencode "query=新能源汽车" \
  -H "Authorization: Bearer $DATAXAPI_API_KEY"
```

Python

```python
# pip install dataxapi
from dataxapi import DataXAPI

dx = DataXAPI()  # reads DATAXAPI_API_KEY
result = dx.weibo.posts.search(query="新能源汽车")
print(result["data"]["items"])
```

TypeScript

```typescript
// npm i @dataxapi/sdk
import { DataXAPI } from "@dataxapi/sdk";

const dx = new DataXAPI(); // reads DATAXAPI_API_KEY
const result = await dx.weibo.posts.search({ query: "新能源汽车" });
console.log(result.data.items);
```

命令行

```bash
dataxapi call weibo.posts.search 'query=新能源汽车'
```

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

```jsonc
{
  "code": "ok",
  "request_id": "814a139c-cdb8-4a40-ac78-d5eea33f4a49",
  "data": {
    "items": [
      {
        "id": "5236052452850013",
        "url": "https://weibo.com/6203910512/imMkNQ4Yv",
        "type": "image",
        "text": "周末的新能源汽车日常，随手记录一下",
        "published_at": "2026-10-12T18:01:10.000Z",
        "author": {
          "id": "6779824410",
          "name": "山野咖啡馆",
          "avatar_url": "https://tvax1.sinaimg.cn/crop.0.0.512.512.180/E3e34Zyl6RyCChKcvEs7K6EZ.jpg",
          "verified": false,
          "followers": 2568
        },
        "metrics": { "likes": 0, "comments": 3, "reposts": 0 },
        "images": [
          "https://tvax1.sinaimg.cn/large/zhuR7jHU35sRnwVn0Z3jHZz1.jpg",
          "https://tvax1.sinaimg.cn/large/OovUGuApFODFZj7FAMuTAB4S.jpg",
          // … 另有 2 条
        ],
        "hashtags": null
      },
      // … 另有 8 条
    ]
  },
  "page": {
    "next_cursor": "c1.Zaf7tnLyz10UhVmeSCiY-wqUpL2K-Pv9eZq__BRv",
    "cursor_expires_at": "2026-10-12T20:03:07.000Z",
    "has_more": true,
    "returned": 9
  },
  "warnings": [],
  "meta": {
    "capability": "weibo.posts.search",
    "result_status": "complete",
    "fetched_at": "2026-10-12T19:03:07.000Z",
    "cached": false,
    "replayed": false,
    "unavailable": {
      "title": "platform",
      "lang": "capability",
      "author.username": "platform",
      "metrics.shares": "platform",
      "metrics.favorites": "capability",
      "metrics.views": "capability",
      "mentions": "capability",
      "is_pinned": "capability",
      "post_id": "platform",
      "parent_id": "platform",
      "root_id": "platform"
    },
    "billing": {
      "amount": "0.002",
      "currency": "USD",
      "balance_after": "9.998"
    }
  }
}
```

### 第 2 步：微博评论

把微博编号放进 `id`，取一页评论，约 20 条，带 IP 属地；下一页用 `page.next_cursor`。（[微博评论](https://dataxapi.com/zh/apis/weibo/posts/comments/list/)，$0.0020 / 一次）

cURL

```bash
curl -G "https://api.dataxapi.com/v1/weibo/posts/comments/list" \
  --data-urlencode "id=5352434046339577" \
  -H "Authorization: Bearer $DATAXAPI_API_KEY"
```

Python

```python
# pip install dataxapi
from dataxapi import DataXAPI

dx = DataXAPI()  # reads DATAXAPI_API_KEY
result = dx.weibo.posts.comments.list(id="5352434046339577")
print(result["data"]["items"])
```

TypeScript

```typescript
// npm i @dataxapi/sdk
import { DataXAPI } from "@dataxapi/sdk";

const dx = new DataXAPI(); // reads DATAXAPI_API_KEY
const result = await dx.weibo.posts.comments.list({ id: "5352434046339577" });
console.log(result.data.items);
```

命令行

```bash
dataxapi call weibo.posts.comments.list id=5352434046339577
```

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

```jsonc
{
  "code": "ok",
  "request_id": "fa38736b-0eeb-43ec-af8d-6dfed79989b4",
  "data": {
    "items": [
      {
        "id": "5253368837152553",
        "text": "收藏了，周末就去试试",
        "published_at": "2026-09-23T14:03:52.000Z",
        "author": {
          "id": "6802897337",
          "name": "阿杰爱折腾",
          "avatar_url": "https://tvax1.sinaimg.cn/crop.0.0.512.512.180/hFDQqZ0eykmuSoczNDhhphXJ.jpg"
        },
        "metrics": { "likes": 20, "comments": 11 },
        "post_id": "5267001718823362",
        "parent_id": null,
        "root_id": null
      },
      // … 另有 19 条
    ]
  },
  "page": {
    "next_cursor": "c1.LRIoesC7sc0iuzzCBkU3T8z207doNiGKjj2FzQDa",
    "cursor_expires_at": "2026-10-12T20:01:34.000Z",
    "has_more": true,
    "returned": 20
  },
  "warnings": [],
  "meta": {
    "capability": "weibo.posts.comments.list",
    "result_status": "complete",
    "fetched_at": "2026-10-12T19:01:34.000Z",
    "cached": false,
    "replayed": false,
    "unavailable": { "url": "platform", "author.username": "platform" },
    "billing": {
      "amount": "0.002",
      "currency": "USD",
      "balance_after": "9.998"
    }
  }
}
```

## 示例花多少钱

两页搜索结果，再取 10 条微博各一页评论

| 接口 | 调用次数 | 单价 | 小计 |
| --- | --- | --- | --- |
| [微博实时搜索](https://dataxapi.com/zh/apis/weibo/posts/search/) | 2 | $0.0020 | $0.0040 |
| [微博评论](https://dataxapi.com/zh/apis/weibo/posts/comments/list/) | 10 | $0.0020 | $0.0200 |
| 合计 | 12 |  | $0.0240 |

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

## 在 AI 里做（MCP）

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

这样说：在微博搜“新能源汽车”，取评论最多的 10 条微博的评论，整理成一张表，再总结大家在吵什么。

代理发给 call 工具的参数：

```json
{
  "capability": "weibo.posts.search",
  "query": "新能源汽车",
  "idempotency_key": "<a new UUID>"
}
```

[了解 MCP 服务](https://dataxapi.com/zh/mcp/)

## 用 Skill 做

“评论与口碑”这个 Skill 把这件事做成了现成的任务，带花费上限。 “用户在这条内容下面夸什么、骂什么？” 它的示例运行：3 次调用，最多 $0.0060。 [评论与口碑](https://dataxapi.com/zh/skills/comments/)

## 为什么用 DataXAPI

- 稳定：近 30 天接口可用 99.9%，状态页公开，可以自己核对。
- 快：近 7 天付费调用的中位耗时 1.6 秒（2026-11-06 统计）。
- 省 token：微博的 11 个接口各取一份录制的真实返回，平台原始 JSON 合计 55.1 万 token，AI 通过 DataXAPI 的 MCP 读到的只有 1.7 万 token，少 97%；直接调接口拿到的 JSON 也少 94%（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 次，不用绑卡。

## 要知道的

- 要长微博全文，用 `weibo.posts.get`。不用微博账号和 Cookie。
- 热搜榜用 `weibo.trends.list`，50 个词。
- 不写代码也行：把 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 = "新能源汽车"
PAGES, POSTS = 2, 10

# 1. Two pages of posts for the search terms, newest first.
posts, cursor = [], None
for _ in range(PAGES):
    page = run("weibo.posts.search", {"query": QUERY, **({"cursor": cursor} if cursor else {})})
    posts += page["data"]["items"]
    cursor = page["page"]["next_cursor"]
    if not page["page"]["has_more"]:
        break

# 2. A page of comments under the posts with the most comments.
rows = []
for post in sorted(posts, key=lambda each: -(each["metrics"].get("comments") or 0))[:POSTS]:
    for comment in run("weibo.posts.comments.list", {"id": post["id"]})["data"]["items"]:
        rows.append([post.get("text"), post["metrics"].get("reposts"), post["metrics"].get("comments"), comment.get("text"), comment["metrics"].get("likes")])

fetched = len(rows)
with open("weibo-comments.csv", "w", newline="", encoding="utf-8") as file:
    csv.writer(file).writerows([["post", "reposts", "comments", "comment", "comment_likes"], *rows])

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

## 用到的接口

- [微博实时搜索](https://dataxapi.com/zh/apis/weibo/posts/search/)
- [微博评论](https://dataxapi.com/zh/apis/weibo/posts/comments/list/)

## 微博的更多内容

- [微博 API](https://dataxapi.com/zh/apis/weibo/)
- [微博数据接口哪里有？帖子、评论、热搜怎么取（2026）](https://dataxapi.com/zh/answers/weibo-data-apis/)
- [微博 MCP：在 Claude、Cursor 里查微博和热搜（2026）](https://dataxapi.com/zh/answers/weibo-mcp/)
- [中文社媒品牌监测怎么做？微博、抖音、小红书一起查（2026）](https://dataxapi.com/zh/answers/chinese-social-media-brand-monitoring/)

---

目录修订号 9d3b7fa5a896745d。 [网页版](https://dataxapi.com/zh/guides/weibo-api-python/)
