# 怎麼抓取 B 站影片下面的評論？

> 按 BV 號拉取任意公開 B 站影片的評論：正文、點贊、回覆數、IP 屬地和時間。每頁費用、匯出 CSV 的指令碼，以及彈幕能不能拿。

網頁版：https://okdata.online/zh-hant/answers/bilibili-video-comments-api/

**簡短回答：**用 B站影片評論介面，傳影片的 BV 號：每次呼叫返回約 20 條評論，帶正文、點贊、回覆數、IP 屬地和時間，$0.002。1,000 條評論共 $0.10，不用登入，也不用 Cookie。彈幕這裡拿不到，只有彈幕總數。

假設一位數碼 UP 主發了二十分鐘的拆機影片，評論區有三千條。一條條看要一個下午；拉進表格讓模型按吐槽點歸類，幾分鐘就完事，花費 $0.30。你只需要影片連結裡的 BV 號。

## 用哪個介面

[B站影片評論](/zh/apis/bilibili/videos/comments/list/)傳 `id`（BV 號，比如 `BV1xx411c7mD`），`sort` 選 `hot`（按熱度）或 `latest`（按時間）。每條評論有：

- `text` 正文、`published_at` 時間和 `likes` 點贊數
- `replies` 樓中樓回覆數；如果這一條本身是回覆，`parent_id` 指向它回覆的那條
- `ip_location`，也就是評論旁邊顯示的 IP 屬地
- `author`，含暱稱和 mid

先不知道該看哪些影片，就用 [B站影片搜尋](/zh/apis/bilibili/videos/search/)找，每頁 $0.002，再按評論數排一下。

## 費用

| 任務 | 呼叫次數 | 費用 |
|---|---|---|
| 一個影片最熱的 200 條評論 | 10 | $0.02 |
| 1,000 條評論 | 50 | $0.10 |
| 搜出 10 個測評影片，每個 300 條評論 | 1 + 150 | $0.302 |

## 匯出 CSV 的指令碼

```python
import csv, os, requests

URL = "https://api.okdata.online/v1/bilibili/videos/comments/list"
H = {"Authorization": f"Bearer {os.environ['OKDATA_API_KEY']}"}

def comments(bv, sort="latest", max_pages=50):
    cursor = None
    for _ in range(max_pages):
        params = {"id": bv, "sort": sort, **({"cursor": cursor} if cursor else {})}
        body = requests.get(URL, headers=H, params=params, timeout=60).json()
        if body["code"] != "ok":
            raise RuntimeError(f"{body['code']}: {body['message']}")
        yield from body["data"]["items"]
        if not body["page"]["has_more"]:
            return
        cursor = body["page"]["next_cursor"]

with open("comments.csv", "w", newline="", encoding="utf-8-sig") as f:
    w = csv.writer(f)
    w.writerow(["時間", "點贊", "回覆數", "IP屬地", "評論"])
    for c in comments("BV1xx411c7mD"):
        w.writerow([c["published_at"], c["likes"], c["replies"], c["ip_location"], c["text"]])
```

檔案用 `utf-8-sig` 編碼，Excel 開啟中文才不會亂碼。

## 彈幕能拿嗎

目前介面目錄裡沒有彈幕內容，只有彈幕總數：搜尋結果或影片詳情加 `view=full`，看 `ext.danmaku`。真要彈幕原文的話，社群維護的 bilibili-API-collect 文件寫了彈幕介面的用法，開源 Python 庫 bilibili-api 也能下載，前提是有影片的 cid。cid 可以從[影片詳情](/zh/apis/bilibili/videos/get/)的 `ext.cid` 拿到。

## 容易踩的坑

- `hot` 拿到的是大家最認同的那些評論，`latest` 才能按時間完整覆蓋。要分析整個影片的情緒，用 `latest`。
- 樓中樓只計數、不展開。一條下面吵了四十樓，在結果裡也只是一行，`replies` 是 40。
- UP 主關閉評論或刪掉的評論，結果裡就沒有。
- 評論是陌生人寫的。交給模型讀的時候，提示它把這些文字當資料，不要當成指令執行。

## 別的辦法

只看一個影片、粗略過一遍，直接刷評論區就行。要長期、大量地抓，並且有人維護，開源的 bilibili-api 不花錢。評論資料怎麼用在口碑分析上，可以看[口碑監測方案](/zh/solutions/word-of-mouth/)。

## 用到的介面

- [B站影片評論](https://okdata.online/zh/apis/bilibili/videos/comments/list/) `bilibili.videos.comments.list`：$0.002/次 · 每頁約 20 條評論
- [B站影片搜尋](https://okdata.online/zh/apis/bilibili/videos/search/) `bilibili.videos.search`：$0.002/次 · 每頁約 20 條影片
- [B站影片詳情](https://okdata.online/zh/apis/bilibili/videos/get/) `bilibili.videos.get`：$0.002/次

## 更多B站內容

- [B站 API](https://okdata.online/zh/apis/bilibili/)
- [B站 API Python 教程：搜尋、影片資料、評論和熱門榜（2026）](https://okdata.online/zh/guides/bilibili-api-python/)
- [B 站的 mid（UID）是什麼，從哪裡拿到？](https://okdata.online/zh/answers/bilibili-mid-uid/)
- [怎麼抓取 B 站影片下面的評論？](https://okdata.online/zh/answers/bilibili-video-comments-api/)
- [ChatGPT 或 Claude 能總結 B 站影片嗎？（2026）](https://okdata.online/zh/answers/can-ai-summarize-bilibili-video/)
- [B 站 BV 號和 AV 號是什麼關係，資料庫裡該存哪個？](https://okdata.online/zh/answers/bilibili-bv-vs-av-number/)
- [想找某個領域的 B 站 UP 主做推廣，怎麼篩？](https://okdata.online/zh/answers/bilibili-find-up-creators-for-sponsorship/)
- [B站有新影片提到我們產品時，怎麼及時知道？](https://okdata.online/zh/answers/bilibili-new-videos-keyword-alert/)
- [評論介面](https://okdata.online/zh/roles/posts-comments-list/)
- [內容詳情介面](https://okdata.online/zh/roles/posts-get/)
- [內容搜尋介面](https://okdata.online/zh/roles/posts-search/)
- [B站熱搜榜：今日榜單](https://okdata.online/zh/tools/hot-search/bilibili/)

## 資料來源

這個問題出現過的地方（讀取於 2026-11-17）：

- https://github.com/LSQYES/BilibiliCommentsCrawler/issues/9

更新於 2026-11-12
