# YouTube Comments Scraper (`outspoken_strategy/youtube-comments-scraper`) Actor

Scrape the comments of one or MANY YouTube videos in a single run. Returns text, author, likes, thread structure (parent/depth) and the source video itself. Top or newest-first order, optional replies. No login, no API quota.

- **URL**: https://apify.com/outspoken\_strategy/youtube-comments-scraper.md
- **Developed by:** [code craker](https://apify.com/outspoken_strategy) (community)
- **Categories:** Social media, Videos, E-commerce
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $15.00 / 1,000 results

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

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

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
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.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use 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

Apify actor that scrapes the comments of one or **many** YouTube videos in a single
run and exports them as structured data — no login, no cookies, no YouTube API quota.

It reads the entry token from the video's watch page and pages through YouTube's own
InnerTube `/youtubei/v1/next` API (the same requests the site itself makes). Requests
go over plain HTTP first (fast and cheap); if YouTube blocks that, the actor
automatically escalates to a real Chrome browser for the rest of the run — API
requests then run inside the page as same-origin fetches.

### Features

- **Batched**: pass many video URLs and they are all scraped in ONE actor run
  (`maxComments` applies per video). Results are pushed after each video, so an
  abort or timeout keeps everything collected so far.
- Any video reference works: `youtube.com/watch?v=...`, `youtu.be/...` short links,
  `/shorts/...` links, or a bare 11-character video id.
- `top` (YouTube's ranked order) or `newest` first.
- Replies included with full thread structure (`parentCommentId` + `depth`), or
  top-level comments only (`includeReplies: false`). Top-level comments are
  collected first; replies fill the remaining budget.
- The source video itself is emitted too (flagged `is_source_post: true`) with
  title, channel, views, exact publish date and total comment count; disable with
  `includeSourcePost: false`. Videos with disabled comments are flagged
  (`commentsDisabled: true`) instead of failing.
- Automatic block recovery: fresh proxy IP on each retry, plain HTTP → real Chrome
  escalation, EU consent interstitial bypassed via cookies.
- When a run ends with 0 results, the last page fetched is saved as `DEBUG_HTML`
  in the run's key-value store.

### Input

```json
{
    "urls": [
        "https://www.youtube.com/watch?v=XXaUd0fGpOs",
        "https://youtu.be/SSE4M0gcmvE"
    ],
    "maxComments": 100,
    "commentsSort": "top",
    "includeReplies": true,
    "includeSourcePost": true,
    "proxyConfiguration": {
        "useApifyProxy": true,
        "apifyProxyGroups": ["RESIDENTIAL"],
        "apifyProxyCountry": "US"
    }
}
````

`startUrls` (`[{ "url": ... }]`) is accepted as an alternative to `urls` and merged
with it. `resultsLimit` is accepted as an alias for `maxComments`.

### Output

One dataset item per comment. Every item carries `postId` / `postUrl` / `inputUrl`,
so comments from a multi-video run can always be attributed back to their source
video.

```json
{
    "id": "Ugw4obgfNOpuN6L96qF4AaABAg",
    "url": "https://www.youtube.com/watch?v=XXaUd0fGpOs&lc=Ugw4obgfNOpuN6L96qF4AaABAg",
    "text": "Full text of the comment...",
    "author": "@some_user",
    "authorChannelId": "UCQLsJdT08EKD_7boRxYusGw",
    "authorProfileUrl": "https://www.youtube.com/channel/UCQLsJdT08EKD_7boRxYusGw",
    "authorAvatar": "https://yt3.ggpht.com/...",
    "isCreator": false,
    "isVerified": false,
    "likeCount": 52,
    "repliesCount": 3,
    "edited": false,
    "parentCommentId": null,
    "depth": 0,
    "publishedTimeText": "14 hours ago",
    "created_at": "2026-07-08T18:53:19.009Z",
    "postId": "XXaUd0fGpOs",
    "postUrl": "https://www.youtube.com/watch?v=XXaUd0fGpOs",
    "inputUrl": "https://www.youtube.com/watch?v=XXaUd0fGpOs",
    "commentsSort": "top",
    "is_source_post": false
}
```

- `parentCommentId` is `null` for a top-level comment; otherwise the id of the
  comment it replies to (YouTube threads are exactly two levels deep). A reply's
  own id is `parentId.replyId`.
- `created_at` is APPROXIMATE: YouTube only exposes relative publish times for
  comments ("2 weeks ago"); the raw value is kept in `publishedTimeText`.
- `isCreator` marks the video's own channel commenting (YouTube's Creator badge) —
  the equivalent of Reddit's `isSubmitter`/OP.
- The source video item has `is_source_post: true` with `title`, `description`,
  `channelName`, `viewCount`, `numComments` and an EXACT `created_at` (watch pages
  expose the real publish date).

### Integration (scraping-tool)

Batched, like the other comment scrapers in `scrapeCommentsForPostsBatched`.
Add a branch to `scrapingService.scrapeCommentsBatch`:

```js
} else if (actor === 'outspoken_strategy/youtube-comments-scraper') {
    delete input.startUrls;
    input.urls = urls;
    input.maxComments = cappedComments(input.maxComments ?? resultsLimit);
    input.includeSourcePost = input.includeSourcePost ?? false;
    input.includeReplies = input.includeReplies ?? false; // match FB: top-level only
    input.proxyConfiguration = input.proxyConfiguration ?? { useApifyProxy: true, apifyProxyGroups: ['RESIDENTIAL'], apifyProxyCountry: 'US' };
}
```

Attribution in `_matchCommentToPost` (platform `youtube`): match on `item.postUrl`,
`item.inputUrl` or `item.postId` — a good `_postMatchKey` is the video id extracted
with `/[?&]v=([A-Za-z0-9_-]{11})/` (plus the `youtu.be`/`shorts` variants).

Normalization hints: `likesCount` ← `likeCount`, `repliesCount` is already named,
`createdTime` ← `created_at` (approximate), `parentCommentId` is already named, and
author fields are flat (`author`, `authorChannelId`, `authorProfileUrl`).

### Local development

```bash
npm install
echo '{ "urls": ["https://www.youtube.com/watch?v=XXaUd0fGpOs"], "maxComments": 25, "proxyConfiguration": { "useApifyProxy": false } }' > storage/key_value_stores/default/INPUT.json
npm start
```

Deploy with `apify push`.

# Actor input Schema

## `urls` (type: `array`):

URLs of the YouTube videos whose comments you want to scrape — one or MANY videos per run. Any form works: youtube.com/watch?v=..., youtu.be/... short links, /shorts/... links, or a bare 11-character video id. De-duplicated by video.

## `startUrls` (type: `array`):

Alternative way to provide the video URLs as a request list of { "url": ... } objects. Merged with "urls" and de-duplicated by video.

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

Maximum number of comments to fetch PER video (replies count towards this limit). The source video itself is also emitted (flagged is\_source\_post) and does not count.

## `commentsSort` (type: `string`):

Which comments YouTube puts first — matters when a video has more comments than maxComments. "top" (YouTube's ranked order) or "newest" (newest first).

## `includeReplies` (type: `boolean`):

Also fetch the replies under each comment (with parentCommentId/depth set). Top-level comments are collected first; replies fill the remaining maxComments budget. Uncheck to keep only top-level comments.

## `includeSourcePost` (type: `boolean`):

Also emit one dataset item for the video itself (flagged is\_source\_post: true) with its title, channel, views, publish date and total comment count. Uncheck to get comments only.

## `proxyConfiguration` (type: `object`):

Proxy to route traffic through. Residential proxies are recommended — YouTube captchas or blocks flagged datacenter IPs.

## `headless` (type: `boolean`):

The actor fetches over plain HTTP and only falls back to a Chrome browser when YouTube blocks it. Uncheck to run that fallback browser headed (useful only for local debugging).

## Actor input object example

```json
{
  "urls": [
    "https://www.youtube.com/watch?v=XXaUd0fGpOs"
  ],
  "startUrls": [],
  "maxComments": 100,
  "commentsSort": "top",
  "includeReplies": true,
  "includeSourcePost": true,
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ],
    "apifyProxyCountry": "US"
  },
  "headless": true
}
```

# 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 = {
    "urls": [
        "https://www.youtube.com/watch?v=XXaUd0fGpOs"
    ],
    "startUrls": [],
    "proxyConfiguration": {
        "useApifyProxy": true,
        "apifyProxyGroups": [
            "RESIDENTIAL"
        ],
        "apifyProxyCountry": "US"
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("outspoken_strategy/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 = {
    "urls": ["https://www.youtube.com/watch?v=XXaUd0fGpOs"],
    "startUrls": [],
    "proxyConfiguration": {
        "useApifyProxy": True,
        "apifyProxyGroups": ["RESIDENTIAL"],
        "apifyProxyCountry": "US",
    },
}

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

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

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

```

## CLI example

```bash
echo '{
  "urls": [
    "https://www.youtube.com/watch?v=XXaUd0fGpOs"
  ],
  "startUrls": [],
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ],
    "apifyProxyCountry": "US"
  }
}' |
apify call outspoken_strategy/youtube-comments-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=outspoken_strategy/youtube-comments-scraper",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "YouTube Comments Scraper",
        "description": "Scrape the comments of one or MANY YouTube videos in a single run. Returns text, author, likes, thread structure (parent/depth) and the source video itself. Top or newest-first order, optional replies. No login, no API quota.",
        "version": "0.0",
        "x-build-id": "SO2hZwxRBtdgKHCNI"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/outspoken_strategy~youtube-comments-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-outspoken_strategy-youtube-comments-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/outspoken_strategy~youtube-comments-scraper/runs": {
            "post": {
                "operationId": "runs-sync-outspoken_strategy-youtube-comments-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/outspoken_strategy~youtube-comments-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-outspoken_strategy-youtube-comments-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "properties": {
                    "urls": {
                        "title": "Video URLs",
                        "type": "array",
                        "description": "URLs of the YouTube videos whose comments you want to scrape — one or MANY videos per run. Any form works: youtube.com/watch?v=..., youtu.be/... short links, /shorts/... links, or a bare 11-character video id. De-duplicated by video.",
                        "items": {
                            "type": "string"
                        }
                    },
                    "startUrls": {
                        "title": "Video URLs (request list)",
                        "type": "array",
                        "description": "Alternative way to provide the video URLs as a request list of { \"url\": ... } objects. Merged with \"urls\" and de-duplicated by video.",
                        "items": {
                            "type": "object",
                            "required": [
                                "url"
                            ],
                            "properties": {
                                "url": {
                                    "type": "string",
                                    "title": "URL of a web page",
                                    "format": "uri"
                                }
                            }
                        }
                    },
                    "maxComments": {
                        "title": "Max comments per video",
                        "minimum": 1,
                        "maximum": 5000,
                        "type": "integer",
                        "description": "Maximum number of comments to fetch PER video (replies count towards this limit). The source video itself is also emitted (flagged is_source_post) and does not count.",
                        "default": 100
                    },
                    "commentsSort": {
                        "title": "Comments sort",
                        "enum": [
                            "top",
                            "newest"
                        ],
                        "type": "string",
                        "description": "Which comments YouTube puts first — matters when a video has more comments than maxComments. \"top\" (YouTube's ranked order) or \"newest\" (newest first).",
                        "default": "top"
                    },
                    "includeReplies": {
                        "title": "Include replies",
                        "type": "boolean",
                        "description": "Also fetch the replies under each comment (with parentCommentId/depth set). Top-level comments are collected first; replies fill the remaining maxComments budget. Uncheck to keep only top-level comments.",
                        "default": true
                    },
                    "includeSourcePost": {
                        "title": "Include the source video",
                        "type": "boolean",
                        "description": "Also emit one dataset item for the video itself (flagged is_source_post: true) with its title, channel, views, publish date and total comment count. Uncheck to get comments only.",
                        "default": true
                    },
                    "proxyConfiguration": {
                        "title": "Proxy configuration",
                        "type": "object",
                        "description": "Proxy to route traffic through. Residential proxies are recommended — YouTube captchas or blocks flagged datacenter IPs.",
                        "default": {
                            "useApifyProxy": true,
                            "apifyProxyGroups": [
                                "RESIDENTIAL"
                            ],
                            "apifyProxyCountry": "US"
                        }
                    },
                    "headless": {
                        "title": "Run browser headless",
                        "type": "boolean",
                        "description": "The actor fetches over plain HTTP and only falls back to a Chrome browser when YouTube blocks it. Uncheck to run that fallback browser headed (useful only for local debugging).",
                        "default": true
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
