# 怎麼把 YouTube 影片評論匯出成 CSV 或 Excel？

> 把 YouTube 影片的評論匯出成 Excel 能直接開啟的 CSV：正文、作者、點贊、回覆數和日期。每 1,000 條評論的費用和 Python 指令碼。

網頁版：https://okdata.online/zh-hant/answers/export-youtube-comments-csv/

**簡短回答：**用 YouTube 影片評論介面（/v1/youtube/videos/comments/list）逐頁拉取，每條評論寫一行 CSV：每頁約 20 條，$0.002，1,000 條評論共 $0.10。每行有正文、作者、點贊、回覆數和日期；用帶 BOM 的 UTF-8 儲存，Excel 開啟表情和中文都不會亂碼。

上週發的產品測評影片已經有 3,000 條評論，市場負責人要你明天之前整理成表格，按點贊排好，方便團隊給吐槽和功能需求打標籤。超過幾十條，從網頁上覆制貼上就沒法幹了，寫個小指令碼幾分鐘就能搞定。

## 用哪個介面

[YouTube 影片評論](/zh/apis/youtube/videos/comments/list/)傳影片 `id` 和 `sort`（`top` 按熱門，`latest` 按最新），每次返回約 20 條，每條帶 `text`、`author`、`likes`、`replies` 和 `published_at`。把 `page.next_cursor` 作為 `cursor` 傳回去，直到 `page.has_more` 為 false。

## 指令碼

```python
import csv, os, requests

API = "https://api.okdata.online/v1/youtube/videos/comments/list"
H = {"Authorization": f"Bearer {os.environ['OKDATA_API_KEY']}"}
VIDEO = "dQw4w9WgXcQ"   # 連結裡 v= 後面那一段
MAX_PAGES = 150         # 約 3,000 條評論

rows, cursor = [], None
for _ in range(MAX_PAGES):
    params = {"id": VIDEO, "sort": "top", **({"cursor": cursor} if cursor else {})}
    body = requests.get(API, headers=H, params=params, timeout=60).json()
    if body["code"] != "ok":
        raise RuntimeError(f"{body['code']}: {body['message']}")
    for c in body["data"]["items"]:
        rows.append([c["id"], c["published_at"], c["author"]["name"], c["likes"], c["replies"], c["text"]])
    if not body["page"]["has_more"]:
        break
    cursor = body["page"]["next_cursor"]

with open(f"{VIDEO}-comments.csv", "w", newline="", encoding="utf-8-sig") as f:
    w = csv.writer(f)
    w.writerow(["comment_id", "published_at", "author", "likes", "replies", "text"])
    w.writerows(rows)
print(len(rows), "條評論已儲存")
```

`utf-8-sig` 會在檔案開頭寫一個 BOM，Excel 靠它才能正確顯示錶情和中文。評論裡的逗號、換行，`csv` 模組會自動加引號處理。

匯出之後，在 Excel 里加一列標籤，比如吐槽、功能需求、誇獎、提問，按點贊從高到低往下標。點贊多的評論往往代表更多人的看法，先把這一批標完，再決定剩下的要不要細看。

## 費用

| 評論量 | 呼叫次數 | 費用 |
|---|---|---|
| 500 條 | 25 | $0.05 |
| 1,000 條 | 50 | $0.10 |
| 3,000 條 | 150 | $0.30 |

實際翻了幾頁就付幾頁的錢。用 `MAX_PAGES` 提前停下，賬單也就停在那裡。

## 表格裡不會有的東西

- **樓中樓回覆。** 拿到的是一級評論和它的回覆數，回覆內容本身沒有。
- **精確的舊日期。** 日期有時是從 2 個月前這類標籤推算出來的，越早的評論越只能當近似值。
- **評論者所在地。** YouTube 不顯示，這個欄位是 null。

## 其他做法

- **官方 YouTube Data API。** `commentThreads.list` 每次只消耗 1 個配額單位，還帶部分回覆。有 Google key、量又不大的話，它免費，也是更好的選擇。
- **youtube-comment-downloader。** 開源命令列工具，在你的網路上能跑通的話，導一次很方便；它的 issue 裡還有人分享了轉成 Excel 的寫法。
- **手工複製。** 50 條以內，直接複製貼上也行。

想大批次讀懂評論在說什麼，可以看[口碑分析方案](/zh/solutions/word-of-mouth/)。

## 用到的介面

- [YouTube 影片評論](https://okdata.online/zh/apis/youtube/videos/comments/list/) `youtube.videos.comments.list`：$0.002/次 · 每頁約 20 條評論

## 更多YouTube內容

- [YouTube API](https://okdata.online/zh/apis/youtube/)
- [怎麼匯出某個話題下所有 YouTube 影片的評論](https://okdata.online/zh/guides/youtube-comments-export/)
- [怎麼按關鍵詞搜 YouTube 影片並拿到字幕](https://okdata.online/zh/guides/youtube-video-transcript/)
- [平台改版或者接口出故障，社媒資料介面會怎樣？](https://okdata.online/zh/answers/social-data-api-reliability-failover/)
- [怎麼把 YouTube 影片評論匯出成 CSV 或 Excel？](https://okdata.online/zh/answers/export-youtube-comments-csv/)
- [抓取社交媒體上的公開資料合法嗎？](https://okdata.online/zh/answers/is-scraping-public-social-media-data-legal/)
- [智慧體讀抓來的評論和帖子，怎麼防提示詞注入？](https://okdata.online/zh/answers/prompt-injection-scraped-social-text/)
- [有沒有一個 API 能同時監測品牌在 TikTok、YouTube 和 X 上的討論？](https://okdata.online/zh/answers/social-listening-api-tiktok-youtube-x/)
- [採集 1000 條抖音、TikTok 或 YouTube 評論要花多少錢？](https://okdata.online/zh/answers/social-media-comments-cost-per-1000/)
- [平台官方 API 和第三方資料介面怎麼選（2026）](https://okdata.online/zh/compare/official-apis-vs-data-apis/)
- [怎麼選社交媒體資料 API（2026）](https://okdata.online/zh/compare/social-media-data-apis/)
- [評論介面](https://okdata.online/zh/roles/posts-comments-list/)

## 資料來源

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

- https://github.com/egbertbouman/youtube-comment-downloader/issues/145
- https://github.com/egbertbouman/youtube-comment-downloader/issues/173
- https://www.v2ex.com/t/1255632

更新於 2026-11-12
