# YouTube Comments Scraper | Comments, Replies, Top & Newest (`hridayrungta/youtube-comments-scraper`) Actor

Alternative YouTube API with no limits or quotas. Extract YouTube comments and reply threads from any video: text, author, likes, date, pinned/hearted flags. Sort by top or newest. No login, no browser, no proxy. $0.002/run + $0.00015/comment or reply.

- **URL**: https://apify.com/hridayrungta/youtube-comments-scraper.md
- **Developed by:** [Hriday Rungta](https://apify.com/hridayrungta) (community)
- **Categories:** Videos, Social media
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $8.00 / 1,000 actor starteds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

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

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
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.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## 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.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## YouTube Scraper | Videos, Channels, Search & Comments

Extracts YouTube video details, channel video listings, search results, and video comments using YouTube's own public pages and its internal "innertube" API. No login, no API key sign-up, no browser, no proxy.

### What you get

- **Video details**: title, channel, view count, like count, publish date, upload date, category, description, keywords/tags, duration, live-stream flag, thumbnail.
- **Channel videos**: a channel's videos (title, view count, published time, duration, thumbnail), paginated past the first page via YouTube's own innertube API.
- **Search results**: matching videos (title, channel, view count, published time, duration), also paginated.
- **Comments**: top-level comments on a video (author, text, like count, reply count, publish time, pinned flag), also paginated.
- **Incremental mode**: track one or many channels over time. Each run after the first returns only videos published since the last run — no re-scraping, no re-paying for old videos.

### How this works (honestly)

YouTube's own pages embed the same JSON the site's front-end uses to render itself server-side — `ytInitialPlayerResponse` (video details) and `ytInitialData` (channel/search/watch-page context) — plus a `ytcfg` blob carrying an `INNERTUBE_API_KEY`. That key unlocks YouTube's internal "innertube" API (`/youtubei/v1/browse`, `/next`, `/search`), the same well-documented, widely-used mechanism tools like yt-dlp rely on for pagination. This Actor:

1. Fetches the relevant public page (a video, a channel's `/videos` tab, or a search results page).
2. Parses the embedded JSON for the first page of results.
3. Follows the page's own continuation token through the innertube API for further pages, anonymously — confirmed working live for channel videos, search results, and comments alike.

No headless browser, no residential proxy, no login wall to fight — because there isn't one. That keeps this fast, reliable, and cheap, and that cost is passed on to you.

One honesty note: only **top-level** comments are extracted. Expanding every reply thread would mean a separate continuation call per comment, which turns an unpredictable cost into a genuinely unbounded one — so replies are left uncollected, though each comment's `replyCount` tells you how many exist.

### Incremental mode (channels only)

Set `mode: "changes"`. On a channel's first run, it seeds from `firstRunSince` (default 30 days back). Every run after that resumes from a per-channel high-water mark stored in a key-value store. Channel grids only expose a relative publish time ("12d ago", "2w ago", "1mo ago" — confirmed live), not an exact timestamp, so the mark uses that as an approximate cutoff; a remembered set of video ids is the real safety net that guarantees no video is ever billed twice, even right at the boundary. A run cut short by your budget still advances the mark safely.

### Input at a glance

| Field | Description |
|---|---|
| `videoUrls` | Videos to fetch full details for — a URL or bare 11-character id, one per line. |
| `channels` | Channels to list videos from — a handle (`@nasa`), a full URL, or a `UC...` id. |
| `searchQueries` | Search terms to run, one per line. |
| `commentVideoUrls` | Videos to fetch top-level comments for (separate budget from the above). |
| `mode` | `"all"` (default) or `"changes"` (incremental) — channels only. |
| `maxItems` | Budget cap on billed video rows (details + channel + search combined). |
| `maxComments` | Budget cap on billed comment rows. Set `0` to disable comments. |
| `maxCommentsPerVideo` | Cap on comments pulled from any single video. |
| `maxPagesPerSource` | Cap on innertube pagination pages per channel/search/comment video. |
| `firstRunSince` | How far back a channel's first incremental run looks (e.g. `"30 days"`). |

### Billing (pay-per-event)

| Event | Price |
|---|---|
| Actor started | $0.002 — charged once per run, regardless of results |
| Video scraped | $0.0007 — video details, a channel's video, or a search result |
| Comment scraped | $0.00018 |

Real-measured cost on Apify's own infrastructure is dominated by fixed per-run overhead (well under $0.001 even for a large run), so pricing is a flat per-event rate with no hidden per-GB or "with extra fields" tier — every row already includes everything this Actor can extract for it.

# Actor input Schema

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

One or more YouTube videos to fetch comments for, one per line: a full watch/shorts/youtu.be URL or a bare 11-character video id.

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

"top": most-liked/pinned comments first (YouTube's default). "newest": most recently posted comments first.

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

When on, also fetches the reply thread under each top-level comment (capped by the two settings below). Each reply is billed as its own row, same as a comment.

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

Cost cap - you're billed once per top-level comment saved, across all videos in this run.

## `maxCommentsPerVideo` (type: `integer`):

Caps how many top-level comments are pulled from any single video, regardless of the overall Max comment rows budget.

## `maxReplies` (type: `integer`):

Only used when "Include replies" is on. Cost cap - you're billed once per reply saved, across all comments and videos in this run.

## `maxRepliesPerComment` (type: `integer`):

Only used when "Include replies" is on. Caps how many replies are pulled from under any single comment, so one heavily-replied comment can't eat the whole budget.

## `maxPagesPerVideo` (type: `integer`):

How many innertube continuation pages of top-level comments to follow per video before moving on - a safety cap independent of the comment budgets above.

## `maxRetries` (type: `integer`):

Retries with backoff for network errors and 5xx responses.

## Actor input object example

```json
{
  "videoUrls": [
    "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
  ],
  "sortBy": "top",
  "includeReplies": false,
  "maxComments": 1000,
  "maxCommentsPerVideo": 1000,
  "maxReplies": 1000,
  "maxRepliesPerComment": 20,
  "maxPagesPerVideo": 500,
  "maxRetries": 3
}
```

# Actor output Schema

## `results` (type: `string`):

No description

# 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=dQw4w9WgXcQ"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("hridayrungta/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=dQw4w9WgXcQ"] }

# Run the Actor and wait for it to finish
run = client.actor("hridayrungta/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=dQw4w9WgXcQ"
  ]
}' |
apify call hridayrungta/youtube-comments-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,hridayrungta/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/uyKb2C1AnceaZSKJR/builds/dEbEOxm57nbfwG7wl/openapi.json
