Scrape YouTube Comments with Python: No Quota, No OAuth
Scrape YouTube comments with Python: one POST returns up to 100 top or newest comments per video as JSON, plus pagination code and a pandas CSV pipeline.
By Scrape Everything team · · Updated · 11 min read
Last updated: November 12, 2026
TL;DR: To scrape YouTube comments with Python, send one POST to /v1/youtube/comments with a video URL, sort (top or newest) and limit. You get up to 100 top-level comments per video per sort, with no pagination and no replies, as JSON with text, author, likes, reply count, pinned flags and the exact total comment_count. Each request costs 1 credit.
If you need every comment on a video, that cap matters, and the free routes below (the YouTube Data API with nextPageToken, or youtube-comment-downloader) are the better fit. If you need the top 100 or 200 comments from 50 videos, joined to view counts and written to CSV, the hosted call is shorter. This post has working code for both.
Which ways can you get YouTube comments in Python?
Four routes come up in practice, from most official to least.
The YouTube Data API v3
The official route is commentThreads.list. You need a Google Cloud project and an API key; OAuth only comes in for moderating or posting. Per Google's commentThreads.list reference, a call returns up to 100 threads per page and costs 1 quota unit, against a default allocation of 10,000 units per project per day (Google's figures, verified October 2026). To be fair to Google, that's generous for comments alone; it gets tight when the same project also runs search.list at 100 units a call. We covered the quota mechanics in our YouTube Data API quota alternative guide.
yt-dlp
yt-dlp writes comments into the video's info JSON:
yt-dlp --skip-download --write-info-json --write-comments \
--extractor-args "youtube:max_comments=100;comment_sort=top" \
-o "%(id)s" "https://www.youtube.com/watch?v=dQw4w9WgXcQ"That produces dQw4w9WgXcQ.info.json with a comments array, replies included. Drop max_comments and it pages through the whole section. It reads YouTube's internal InnerTube endpoints one continuation token at a time, so a full pull on a video with tens of thousands of comments is slow. When YouTube changes those internal responses you wait for a release. From datacenter IPs, a symptom yt-dlp users report often is YouTube's "Sign in to confirm you're not a bot" response.
youtube-comment-downloader and Selenium
youtube-comment-downloader is the library Stack Overflow answers usually name first: no API key, a Python generator, sorting by popular or recent. It uses the same internal endpoints as yt-dlp, with the same trade-offs.
Selenium or Playwright scroll-scraping is the last resort: scroll, wait for lazy loading, parse the DOM, repeat. It's the slowest option and breaks whenever the markup changes. I wouldn't start a new project on it.
A hosted YouTube comments API
A YouTube comments API is a REST endpoint that returns public comment data as JSON, with the parsing and network side run by the provider. The Scrape Everything YouTube comments endpoint takes one JSON body and returns one JSON object, billed per request that returns data or a final answer.
| YouTube Data API v3 | yt-dlp / youtube-comment-downloader | Scrape Everything youtube.comments | |
|---|---|---|---|
| Setup | Google Cloud project + API key | pip install | API key from signup |
| OAuth for public comments | No | No | No |
| Comments per video | All (paginated, 1 unit per 100) | All, or capped with max_comments | 100 per sort, no pagination |
| Replies | Yes, plus comments.list for full threads | Yes | No, only reply_count |
| Comment date | ISO publishedAt | Relative text, plus a parsed estimate | Relative published_text |
| Sort | relevance or time | Top or new | top or newest |
| Limits | 10,000 units/day per project by default | None set by a vendor; YouTube may block your IP | 60 req/min, 5 concurrent; 300 req/min, 20 concurrent once you buy any pack |
| Who maintains the parser | You (upgrade the library) | Us | |
| Cost | Free within quota | Free, plus your infrastructure | 1 credit per request |
Google figures verified October 2026.
How do I get every comment with the Data API or youtube-comment-downloader?
If you need full coverage of a few videos, do it yourself. Two working snippets.
The Data API, paging with nextPageToken:
import os
from googleapiclient.discovery import build # pip install google-api-python-client
yt = build("youtube", "v3", developerKey=os.environ["YOUTUBE_API_KEY"])
rows, token = [], None
while True:
params = {"part": "snippet", "videoId": "dQw4w9WgXcQ", "maxResults": 100,
"order": "relevance", "textFormat": "plainText"}
if token:
params["pageToken"] = token
resp = yt.commentThreads().list(**params).execute() # 1 quota unit per page
for item in resp["items"]:
s = item["snippet"]["topLevelComment"]["snippet"]
rows.append({"id": item["id"], "author": s["authorDisplayName"],
"text": s["textDisplay"], "likes": s["likeCount"],
"published_at": s["publishedAt"],
"replies": item["snippet"]["totalReplyCount"]})
token = resp.get("nextPageToken")
if not token:
break
print(len(rows), "comments")Read textDisplay with textFormat=plainText. Google's reference says textOriginal is only guaranteed for the comment's own author. For replies, add replies to part: that returns some replies inline, not necessarily all of them, and comments.list with parentId pages the rest.
youtube-comment-downloader, no key at all:
from itertools import islice
from youtube_comment_downloader import YoutubeCommentDownloader, SORT_BY_POPULAR
dl = YoutubeCommentDownloader()
comments = dl.get_comments_from_url("https://www.youtube.com/watch?v=dQw4w9WgXcQ",
sort_by=SORT_BY_POPULAR)
for c in islice(comments, 500): # it's a generator; slice it or it runs to the end
print(c["votes"], c["author"], c["text"][:80])My rule: once you're looping over dozens of videos, retrying blocked IPs and joining comments to video stats by hand, pagination is no longer the hard part. That's the case the rest of this post covers.
How do I scrape YouTube comments with Python in one request?
Any common link works: watch?v=, youtu.be, Shorts, live and embed URLs, or the bare 11-character ID. Live URLs give you the comments under a stream or premiere, not live chat replay, which is a separate thing.
curl -X POST https://api.scrapeeverything.com/v1/youtube/comments \
-H "Authorization: Bearer $SCRAPEEVERYTHING_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ", "sort": "top", "limit": 20}'The response, trimmed to two comments (values are placeholders):
{
"success": true,
"data": {
"video_id": "dQw4w9WgXcQ",
"sort": "top",
"comment_count": 2318,
"comments_fetched": 20,
"has_more": true,
"comments": [
{
"id": "UgzEXAMPLEpinned",
"link": "https://www.youtube.com/watch?v=dQw4w9WgXcQ&lc=UgzEXAMPLEpinned",
"text": "Links from the video are in the description.",
"author": {
"name": "@example_channel",
"channel_id": "UCxxxxxxxxxxxxxxxxxxxxxx",
"handle": "@example_channel",
"avatar_url": "https://yt3.ggpht.com/example",
"is_channel_owner": true,
"is_verified": true
},
"like_count": 1200,
"like_count_text": "1.2K",
"reply_count": 14,
"published_text": "3 weeks ago",
"is_pinned": true,
"is_hearted": false
},
{
"id": "UgwEXAMPLEtop",
"link": "https://www.youtube.com/watch?v=dQw4w9WgXcQ&lc=UgwEXAMPLEtop",
"text": "The part at 4:12 finally made this click for me.",
"author": {
"name": "@example_user",
"channel_id": "UCyyyyyyyyyyyyyyyyyyyyyy",
"handle": "@example_user",
"avatar_url": "https://yt3.ggpht.com/example2",
"is_channel_owner": false,
"is_verified": false
},
"like_count": 8400,
"like_count_text": "8.4K",
"reply_count": 37,
"published_text": "2 weeks ago (edited)",
"is_pinned": false,
"is_hearted": true
}
]
},
"meta": { "credits_charged": 1, "cached": false }
}The same call in Python with requests:
import os
import requests
API = "https://api.scrapeeverything.com"
HEADERS = {"Authorization": f"Bearer {os.environ['SCRAPEEVERYTHING_API_KEY']}"}
res = requests.post(
f"{API}/v1/youtube/comments",
headers=HEADERS,
json={"url": "https://youtu.be/dQw4w9WgXcQ", "sort": "newest", "limit": 100},
timeout=90,
)
data = res.json()["data"]
print(data["comment_count"], "total,", data["comments_fetched"], "fetched")
for c in data["comments"][:5]:
print(c["like_count_text"] or "0", c["author"]["handle"], c["text"][:80])limit accepts 1 to 100 and defaults to 20. limit: 100 still costs 1 credit.
Which response fields need care?
Why is the pinned comment first?
sort: "top" (the default) follows YouTube's own "Top comments" ranking, which isn't a strict sort by likes. sort: "newest" puts the most recent first. The applied sort comes back in data.sort, so store it with the rows.
In both sorts a pinned comment is listed first, matching what a viewer sees, and it bites in two places. In a newest-first timeline, the pinned comment is often weeks older than everything after it, so drop rows where is_pinned is true before treating the list as chronological. And pinned comments usually come from the channel itself, so filter on author.is_channel_owner if you want audience voice only.
There's no cursor parameter. When has_more is true and you want broader coverage, request both top and newest and dedupe on id. That gives you up to 200 unique comments: the most-engaged ones plus the latest.
Why are like counts rounded while comment_count is exact?
YouTube shows comment likes as rounded text such as "8.4K" or "1.2M". You get that raw string in like_count_text and a parsed integer in like_count. A comment with no likes has like_count 0 and like_count_text null. Ranking by like_count works, but above 1,000 likes ties are common, because every count YouTube displays as "1.2K" parses to 1,200. Use reply_count as a tiebreaker. Sums of like_count are approximations, so label them that way. comment_count, the video's total, is exact, which makes it the right denominator for engagement rates.
How do I date comments?
published_text is relative ("2 months ago", "6 years ago (edited)"), not an ISO timestamp. Store your fetch date next to it for rough dating. If you need exact timestamps, that's a reason to use the Data API's publishedAt instead.
How do I handle COMMENTS_DISABLED and NOT_FOUND?
Some videos have comments off; some IDs will be deleted or mistyped. The endpoint separates the two:
| HTTP status | code | Meaning | What to do | Charged |
|---|---|---|---|---|
| 404 | COMMENTS_DISABLED | The video exists, comments are off | Record it, skip the video | Yes |
| 404 | NOT_FOUND | The video doesn't exist | Remove the ID from your list | Yes |
| 429 | RATE_LIMITED / CONCURRENCY_LIMIT | Too many requests | Wait and retry | No |
| 502 / 503 / 504 | e.g. TARGET_BLOCKED, TIMEOUT | Upstream or capacity problem | Retry with backoff | No, refunded |
A 404 is a final answer for that target. Per the errors reference, retrying returns the same result and is charged again, so cache bad IDs on your side. Branch on code, never on message, which is written for humans and may change. Keep the request_id from error bodies if you need to ask support about a result.
How do I turn YouTube comments into a pandas DataFrame and CSV?
The full pipeline uses three endpoints at 1 credit each: youtube.search, youtube.comments and youtube.video.
- Search for up to 50 recent videos on a topic with
youtube.search. - For each video, fetch up to 100 top comments with
youtube.comments, skippingCOMMENTS_DISABLEDandNOT_FOUND. - Fetch exact views, likes and publish date with
youtube.video. - Flatten the nested comment JSON with
pd.json_normalize, join onvideo_idand write a CSV.
import os
import time
import requests
import pandas as pd
API = "https://api.scrapeeverything.com"
HEADERS = {"Authorization": f"Bearer {os.environ['SCRAPEEVERYTHING_API_KEY']}"}
SKIP = {"COMMENTS_DISABLED", "NOT_FOUND"}
def call(action: str, body: dict, retries: int = 3) -> dict | None:
for attempt in range(retries):
res = requests.post(f"{API}/v1/youtube/{action}", headers=HEADERS, json=body, timeout=90)
try:
payload = res.json()
except ValueError:
payload = {}
if payload.get("success"):
return payload["data"]
code = payload.get("code")
if code in SKIP:
print(f"skip {body}: {code}")
return None
if res.status_code in (429, 502, 503, 504) and attempt < retries - 1:
time.sleep(2 ** attempt * 5)
continue
raise RuntimeError(f"{res.status_code} {code}: {payload.get('message')}")
return None
# 1. Find videos (1 credit for up to 50 results)
found = call("search", {"query": "mechanical keyboard review", "type": "video",
"upload_date": "month", "limit": 50})
video_ids = [r["video_id"] for r in found["results"] if r.get("video_id")]
comment_frames, video_rows = [], []
for vid in video_ids:
# 2. Comments first: if they're disabled we skip the stats call too
comments = call("comments", {"id": vid, "sort": "top", "limit": 100, "cache_days": 7})
if comments is None or not comments["comments"]:
continue
df = pd.json_normalize(comments["comments"])
df["video_id"] = vid
df["video_comment_count"] = comments["comment_count"]
comment_frames.append(df)
# 3. Exact video stats
video = call("video", {"id": vid, "cache_days": 7})
if video:
video_rows.append(video)
if not comment_frames:
raise SystemExit("No comments collected")
# 4. Join and export
comments_df = pd.concat(comment_frames, ignore_index=True)
videos_df = pd.json_normalize(video_rows)[
["video_id", "title", "view_count", "like_count", "published_at", "channel.name"]
].rename(columns={
"title": "video_title",
"view_count": "video_views",
"like_count": "video_likes",
"published_at": "video_published_at",
"channel.name": "channel_name",
})
dataset = comments_df.merge(videos_df, on="video_id", how="left")
dataset = dataset[dataset["is_pinned"] != True] # drop pinned creator notes
dataset["comments_per_1k_views"] = dataset["video_comment_count"] / dataset["video_views"] * 1000
cols = ["video_id", "video_title", "channel_name", "video_views", "video_likes",
"video_comment_count", "comments_per_1k_views", "id", "author.handle",
"text", "like_count", "like_count_text", "reply_count", "published_text",
"is_hearted"]
dataset[cols].to_csv("youtube_comments.csv", index=False, encoding="utf-8")
print(len(dataset), "comments from", dataset["video_id"].nunique(), "videos")Illustrative output (your numbers will differ):
skip {'id': 'xxxxxxxxxxx', 'sort': 'top', 'limit': 100, 'cache_days': 7}: COMMENTS_DISABLED
4812 comments from 49 videosWhy the code looks like this:
- Both responses have a
like_count, so the video columns get renamed before the merge. Otherwise pandas adds_xand_ysuffixes and someone will mix them up in a chart later. is_pinned != Trueinstead of~is_pinnedkeeps the filter working even if a column ever arrives with nulls.cache_days: 7means a rerun within a week reads cached results for free, handy while you're still fiddling with the DataFrame. Windows go from 1 to 14 days.encoding="utf-8"matters because comments are full of emoji and non-Latin scripts. If Excel mangles the file, useencoding="utf-8-sig".- The loop is sequential on purpose. The default limits are 60 requests per minute and 5 concurrent, and cache hits still count toward the per-minute limit. If a fast rerun trips
RATE_LIMITED, the retry branch waits.
For one channel's uploads instead of a search, swap step 1 for youtube.videos with the channel handle and limit: 30; it returns up to 30 latest uploads per request (default 12), also 1 credit. The YouTube scraper hub lists every YouTube endpoint, and the OpenAPI spec at https://scrapeeverything.com/openapi.json lets you generate a typed client. The request shape is the same for Instagram comments and TikTok, so one pipeline can cover all three.
How many credits does a 50-video comment dataset cost?
Count requests, not comments. Every call above is 1 credit no matter how many items it returns.
| Step | Endpoint | Calls | Credits |
|---|---|---|---|
| Find 50 videos | youtube.search (limit 50) | 1 | 1 |
| Top 100 comments per video | youtube.comments | 50 | 50 |
| Exact stats per video | youtube.video | 50 | 50 |
| Total | 101 | 101 |
Some variations, using the same per-request pricing:
- Fit it in the free credits. Search with
limit: 49and the run is 1 + 49 + 49 = 99 credits. Or drop step 3:youtube.searchresults already carryview_count, exact for regular video results. That's 1 + 50 = 51 credits, and anewestpass on top makes 101. - Disabled comments. If 4 of the 50 videos have comments off, those 404s are still billed, but the script skips their stats calls: 1 + 50 + 46 = 97 credits.
- A weekly job. 10 search queries, 500 videos, both sorts plus stats is 10 + 1,000 + 500 = 1,510 credits per run, or 6,040 over four weeks. At Builder rates ($0.80 per 1,000) that's about $4.83 a month, so one $19.99 Builder pack covers roughly 16 weekly runs. At Scale rates ($0.50 per 1,000) the same month is about $3.02. Reruns inside your
cache_dayswindow cost nothing, and blocks, timeouts and server errors are refunded automatically.
Now the honest comparison. The same 500 videos on the Data API cost 500 units for top comments, 500 for a time-sorted pass and about 1,000 for 10 search.list calls: around 2,000 of your 10,000 daily units. If you already have a Cloud project and only need YouTube, the Data API is cheaper, and you should use it.
| Job | Best route | Why |
|---|---|---|
| Every comment and reply on a handful of videos, once | yt-dlp or youtube-comment-downloader | Free, full threads, speed doesn't matter |
| All comments with ISO timestamps, within 10,000 units/day | Data API v3 | Exact publishedAt, official, 1 unit per 100 threads |
| Top 100 (plus newest 100) on many videos, joined to video stats | Scrape Everything | No Cloud project, no pagination loop, 1 credit per call |
| Comments from YouTube, Instagram and TikTok in one pipeline | Scrape Everything | Same request shape across platforms |
Credits come in one-time packs and never expire; the credit calculator sizes a recurring job. The 100 free credits at signup run the limit: 49 version of the script once.
Get 100 free credits, no payment details needed. You can sign in with Google or GitHub.
What can I do with the comments next?
If you'd rather not write Python, the same endpoints are tools in our MCP server (@scrapeeverything/mcp) and an n8n node (n8n-nodes-scrapeeverything) for scheduled exports. Pairing comments with the YouTube transcript API guide lets you match reactions to the moment in the video they refer to.
For the next concrete step, load youtube_comments.csv into the pipeline from our sentiment analysis guide for social media comments and score the text column per video.
FAQ
How do I get all comments from a YouTube video?
Page through commentThreads.list with nextPageToken on the YouTube Data API (1 quota unit per 100 threads), or run yt-dlp or youtube-comment-downloader without a cap. The Scrape Everything endpoint stops at 100 top-level comments per sort, so it isn't the tool for complete comment sections.
Does the YouTube comments endpoint return replies?
No. It returns top-level comments only, each with a reply_count. For reply text, use commentThreads.list with the replies part and comments.list with parentId, or yt-dlp.
Why does my scraper only return 20 comments?
With the Scrape Everything endpoint, limit defaults to 20; set it to 100 at the same 1-credit cost. With Selenium, YouTube lazy-loads comments as you scroll, so you only get what loaded before you parsed.
Do I need a Google API key or OAuth?
Not for this endpoint. You need a Scrape Everything API key in the Authorization: Bearer header. There's no Google Cloud project, no OAuth consent screen and no quota units. It only reads public data.
Is it legal to scrape YouTube comments?
The endpoint only returns publicly visible data. Comments still contain personal data such as usernames, so think about storage, retention and how you publish results. Our non-lawyer overview is in is scraping public social media data legal. Scrape Everything isn't affiliated with YouTube or Google.