# YouTube Comments Scraper - export to JSON (`jamhimself/youtube-comments-scraper`) Actor

Scrape YouTube comments to JSON. Input: video URLs or IDs + max comments and sort (top/newest). Output: one row per comment (author, text, likes, replies, timestamp, pinned, video title). No API key. $0.0004 per comment; skipped videos are free.

- **URL**: https://apify.com/jamhimself/youtube-comments-scraper.md
- **Developed by:** [Jaime Martinez](https://apify.com/jamhimself) (community)
- **Categories:** Social media, Agents, AI
- **Stats:** 3 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.24 / 1,000 product comments

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## YouTube Comments Scraper — export YouTube comments to JSON

YouTube Comments Scraper for developers and AI pipelines — export comments from public YouTube videos as clean JSON (author, text, likes, reply count, timestamps, pinned flag), in bulk, with no API key.

YouTube throttles datacenter IPs and changes its comment endpoints often, so naive scrapers and free libraries break in production. This actor runs a hosted residential-proxy + retry layer, is actively maintained, and you only pay for comments actually delivered.

Built for developers and AI builders: sentiment analysis, audience research, content ideas, moderation datasets, and RAG/LLM ingestion of community discussion.

### ⚡ Quick start

Paste this into the Actor's **Input** (JSON view) and hit **Start**:

```json
{
  "videoUrls": ["https://www.youtube.com/watch?v=jNQXAC9IVRw"],
  "maxComments": 100
}
```

Each result row looks like:

```json
{
  "videoId": "jNQXAC9IVRw",
  "url": "https://www.youtube.com/watch?v=jNQXAC9IVRw",
  "videoTitle": "Me at the zoo",
  "author": "@example-user",
  "text": "We're all watching history here.",
  "likeCount": "12K",
  "replyCount": 41,
  "publishedTime": "2 years ago"
}
```

Or run it from the API:

```
POST https://api.apify.com/v2/acts/jamhimself~youtube-comments-scraper/run-sync-get-dataset-items?token=YOUR_APIFY_TOKEN
```

Export as JSON, CSV, or Excel from the run's **Storage** tab.

### What it does

Give it a list of YouTube video URLs or IDs and it returns the comments for each as structured JSON:

- `author`, `authorChannelId`, `authorIsChannelOwner`
- `text` (full comment)
- `likeCount`, `replyCount`, `publishedTime`
- `isPinned`
- `videoId`, `videoTitle`, `channelName`, `url`

Single videos or thousands in one run, up to thousands of comments per video.

### Use cases

- **Sentiment & audience analysis** — feed comments to an LLM for themes, sentiment, FAQs.
- **Content research** — mine what viewers ask for across a channel.
- **Moderation datasets** — collect labeled examples of spam/toxicity.
- **RAG / LLM ingestion** — add community discussion to your knowledge base.

### What you'll pay

**The first 200 comments in every run are free.** After that, **$0.0004 per delivered comment** — no actor-start fee, no subscription. The math is plain:

| Comments delivered in a run | Cost |
|---|---|
| 200 or fewer | $0.00 |
| 1,000 | $0.32 |
| 10,000 | $3.92 |

No subscription, no API key, no minimums. Videos with comments disabled, private, or unavailable are never charged.

*Prices above are the standard rate. Apify Store subscription discounts apply automatically — Bronze −10%, Silver −20%, Gold and above −40% (that is the "from" price shown on this page).*

### Input

| Field | Type | Description |
|---|---|---|
| `videoUrls` | array | **Required.** YouTube video URLs or IDs. Watch, youtu.be, shorts, and live URLs all work. |
| `maxComments` | integer | Max top-level comments per video. Default 100. |
| `sortBy` | string | `top` or `newest`. Default `top`. If YouTube does not expose newest-first ordering for a video, top order is used. |
| `concurrency` | integer | Videos in parallel (1–8). Default 3. |
| `proxyCountryCode` | string | Optional two-letter proxy country code (e.g. `US`). |

### Output

One dataset item per comment. Videos with comments disabled, private, or unavailable are written to a separate `SKIPPED` record (with the reason) and are **never charged**.

### Use as an MCP tool / with AI agents

This actor is automatically exposed as an MCP tool, so AI agents can call it directly — no wrapper code:

```json
{
  "mcpServers": {
    "apify": {
      "url": "https://mcp.apify.com/?tools=jamhimself/youtube-comments-scraper"
    }
  }
}
```

The endpoint is streamable HTTP (authenticate with your Apify token). Any MCP client — Claude, Cursor, or agent frameworks — can pass `videoUrls` and read the comments straight back from the dataset.

### Why YouTube scrapers come back empty (and how this one avoids it)

YouTube serves bot-check and consent interstitials to suspicious traffic and throttles datacenter IPs. Naive scrapers parse those interstitial pages, find no comment section, and wrongly report "no comments" or "comments disabled". This actor detects bot-served pages instead of mislabeling them, retries on fresh sessions, and escalates to residential proxies automatically. It is actively maintained against YouTube's endpoint changes — and if a video still can't be fetched, it lands in the skipped list and you pay nothing.

### FAQ

- **Do I need a YouTube API key?** No. No key, no quota, no OAuth.
- **Replies?** Top-level comments are returned now; threaded replies are coming in a later version.
- **Comments disabled?** Reported in the skipped list, not charged.
- **Is this legal?** It accesses publicly available comment data. You are responsible for complying with YouTube's Terms of Service and applicable law in your use of the output.

**Was this useful?** An honest review helps other people find this Actor — and tells me what to fix next. [Leave a review](https://apify.com/jamhimself/youtube-comments-scraper/reviews).

***

YouTube is a trademark of Google LLC. This actor is not affiliated with or endorsed by YouTube or Google. Built and maintained by Jamhimself LLC.

# Actor input Schema

## `videoUrls` (type: `array`):

YouTube video URLs or IDs — scrape the comments of each as clean JSON (author, text, likes, replies, timestamps). Accepts watch, youtu.be, shorts, and live URLs or raw 11-character video IDs.

## `maxComments` (type: `integer`):

Maximum number of top-level comments to fetch per video.

## `sortBy` (type: `string`):

Comment sort order — top comments or newest first. If YouTube does not expose newest-first ordering for a video, top order is used.

## `concurrency` (type: `integer`):

Parallel videos (1-8) — how many videos to process at the same time.

## `proxyCountryCode` (type: `string`):

Proxy country — optional two-letter code (e.g. US) applied to both datacenter and residential proxies.

## Actor input object example

```json
{
  "videoUrls": [
    "https://www.youtube.com/watch?v=jNQXAC9IVRw"
  ],
  "maxComments": 100,
  "sortBy": "top",
  "concurrency": 3
}
```

# Actor output Schema

## `comments` (type: `string`):

One row per comment: author, text, likes, reply count, and timestamp.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "videoUrls": [
        "https://www.youtube.com/watch?v=jNQXAC9IVRw"
    ],
    "maxComments": 100,
    "sortBy": "top",
    "concurrency": 3
};

// Run the Actor and wait for it to finish
const run = await client.actor("jamhimself/youtube-comments-scraper").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "videoUrls": ["https://www.youtube.com/watch?v=jNQXAC9IVRw"],
    "maxComments": 100,
    "sortBy": "top",
    "concurrency": 3,
}

# Run the Actor and wait for it to finish
run = client.actor("jamhimself/youtube-comments-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "videoUrls": [
    "https://www.youtube.com/watch?v=jNQXAC9IVRw"
  ],
  "maxComments": 100,
  "sortBy": "top",
  "concurrency": 3
}' |
apify call jamhimself/youtube-comments-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,jamhimself/youtube-comments-scraper"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/sHwIMf0vfK8Aiwxd9/builds/PDKxKWDOByUhongdi/openapi.json
