How to scrape YouTube comments and replies with Python
Comments tell you what an audience thinks, asks and wants next. This guide saves a video's comments and replies to a CSV file in Python, then reads the comments of a whole channel.
Updated 5 December 2026 · TTech Solutions
Python: comments to CSV
GET /comments on the YouTube Channel & Video API returns 20 comments a page and a continuation for the next one. A comment's replyToken, passed as token, opens its replies, which come page by page the same way. The script below saves comments and replies into one CSV file; a reply's parent_id is the id of its comment.
- Sign up for free and create an API key in your TTech dashboard.
- Send the key in the
x-api-keyheader. Every call goes tohttps://api.ttechapi.com/v1/youtubeplus the endpoint path. - Set the video and the limits at the top, then run the script.
import csv
import requests
BASE = "https://api.ttechapi.com/v1/youtube"
HEADERS = {"x-api-key": "YOUR_API_KEY"}
def get(path, **params):
data = requests.get(BASE + path, params=params, headers=HEADERS, timeout=60).json()
if data.get("error"): # errors come back as JSON with an error code and a message
raise RuntimeError(f"{data['error']}: {data.get('msg') or data.get('message')}")
return data
VIDEO = "arj7oStGLkU" # a video id or link
MAX_COMMENTS = 100 # top-level comments to save
MAX_REPLIES = 10 # replies to save per comment; 0 skips replies
FIELDS = ["comment_id", "parent_id", "author", "text", "likes", "replies", "date", "pinned", "by_creator"]
def pages(**params):
"""Every page of comments or replies: the first one, then one per continuation token."""
page = get("/comments", **params)
while True:
yield page
if not page.get("continuation"):
return
page = get("/comments", token=page["continuation"])
def row(c, parent_id=""):
return {
"comment_id": c["commentId"],
"parent_id": parent_id, # empty for a top-level comment
"author": c["authorText"],
"text": c["textDisplay"],
"likes": c["likesCount"], # as YouTube shows it: "12" or "3K"
"replies": c.get("replyCount", ""),
"date": c["publishDate"], # YYYY-MM-DD
"pinned": c.get("isPinned", False),
"by_creator": c.get("authorIsChannelOwner", False),
}
def replies_of(comment):
found = []
if MAX_REPLIES > 0 and comment.get("replyToken"):
for page in pages(token=comment["replyToken"]): # a comment's replyToken opens its replies
found += [row(r, comment["commentId"]) for r in page["data"]]
if len(found) >= MAX_REPLIES:
break
return found[:MAX_REPLIES]
rows, saved = [], 0
for page in pages(id=VIDEO, sort_by="newest"): # or sort_by="top"
for c in page["data"]:
if saved >= MAX_COMMENTS:
break
rows.append(row(c))
rows += replies_of(c)
saved += 1
if saved >= MAX_COMMENTS:
break
with open("comments.csv", "w", newline="", encoding="utf-8") as f:
writer = csv.DictWriter(f, fieldnames=FIELDS)
writer.writeheader()
writer.writerows(rows)
print(saved, "comments and", len(rows) - saved, "replies saved to comments.csv")Each page of comments or replies is one call and costs 1 credit: one call per 20 comments, plus at least one for each comment that has replies. Set MAX_REPLIES = 0 to save only top-level comments.

The first page also has commentsCount, the total YouTube shows. A video with comments turned off answers an empty data and a msg that says why.
A whole channel
GET /channel/videos lists a channel's videos, 30 a page. Read the comments of each one with the same paging loop:
import requests
BASE = "https://api.ttechapi.com/v1/youtube"
HEADERS = {"x-api-key": "YOUR_API_KEY"}
def get(path, **params):
data = requests.get(BASE + path, params=params, headers=HEADERS, timeout=60).json()
if data.get("error"): # errors come back as JSON with an error code and a message
raise RuntimeError(f"{data['error']}: {data.get('msg') or data.get('message')}")
return data
def comments_of(video_id, limit=100):
found, page = [], get("/comments", id=video_id, sort_by="top")
while True:
found += page["data"]
if len(found) >= limit or not page.get("continuation"):
return found[:limit]
page = get("/comments", token=page["continuation"])
channel = get("/channel/videos", id="@TED", sort_by="newest") # an @handle, a channel link or a UC id
for video in channel["data"][:10]: # the 10 newest videos
for c in comments_of(video["videoId"]):
print(video["title"], "|", c["authorText"], "|", c["textDisplay"][:80])Analyze them with an LLM
Give the CSV to ChatGPT or Claude, or connect the TTech MCP server and ask directly. The assistant reads the comments with the youtube_comments tool:
- "What are the 10 most common questions in these comments?"
- "Sort the comments into praise, complaints and feature requests, with counts."
- "Which video ideas do viewers ask for most?"
Run this, then type /mcp in Claude Code and sign in to TTech.
claude mcp add --transport http ttech https://mcp.ttechapi.com/mcpOr install our Claude Code plugin from GitHub. It adds the same server and a YouTube research skill. Then type /mcp and sign in.
claude plugin marketplace add ttechapi/claude-plugins
claude plugin install ttech@ttechTo skip the question before each tool call, add "mcp__ttech" to permissions.allow in .claude/settings.json.
- In claude.ai or Claude Desktop, open Customize > Connectors, select + Add and Add custom connector.
- Paste this URL and continue:
https://mcp.ttechapi.com/mcp- Select Connect and sign in with your TTech account.
Add this to ~/.cursor/mcp.json (or .cursor/mcp.json in a project). Then open Cursor's MCP settings and connect TTech to sign in.
{
"mcpServers": {
"ttech": {
"url": "https://mcp.ttechapi.com/mcp"
}
}
}Add the server, then sign in through the browser.
codex mcp add ttech --url https://mcp.ttechapi.com/mcp
codex mcp login ttech- In ChatGPT on the web, open Plugins, select + and Add custom MCP server (on plans that allow custom MCP servers).
- Paste this URL and choose OAuth:
https://mcp.ttechapi.com/mcp- Sign in with your TTech account and review the tools.
Add this to .vscode/mcp.json, then start the server and sign in.
{
"servers": {
"ttech": {
"type": "http",
"url": "https://mcp.ttechapi.com/mcp"
}
}
}FAQ
Why is likes "3K" and not a number?
YouTube shows exact likes only under 1,000. Above that you get YouTube's rounded text.
Can I get every comment of a big video?
Yes, page by page: each page has 20 comments and a continuation token for the next one.
How do I get the replies of a comment?
Pass the comment's replyToken as token to GET /comments. Replies come page by page with their own continuation token, like comments.
Do I need the YouTube API key?
No. A TTech API key is enough, and there is no Google quota.
Services in this guide
YouTube Channel & Video API
Channels, videos, Shorts, comments, transcripts, search and playlists as JSON. A YouTube Data API alternative with no Google key and no daily quota.
DetailsYouTube Comments Scraper
A YouTube video's comments and replies, 20 a page: text, author, likes, reply count, pinned and creator-hearted flags, top or newest first.
DetailsMore guides
How to get a YouTube transcript with an API (Python, no YouTube API key)
Get the captions of any public video as plain text or timed segments, in Python or JavaScript, for one video or whole channels.
Guide ReadYouTube API quota exceeded? Get YouTube data without a Google key or daily quota
What the 10,000-unit quota really allows, your options when it runs out, and how to switch to an API with no Google quota.
Guide ReadYouTube MCP server for Claude, Claude Code, Cursor, Codex and ChatGPT
Connect YouTube search, video details, transcripts and comments to your AI assistant with one MCP server, with setup steps for each client.
Guide Read