# Youtube Comments Scraper (`scraply/youtube-comments-scraper`) Actor

- **URL**: https://apify.com/scraply/youtube-comments-scraper.md
- **Developed by:** [Scraply](https://apify.com/scraply) (community)
- **Categories:** Automation, Lead generation, Social media
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, NaN bookmarks
- **User rating**: No ratings yet

## Pricing

$19.99/month + usage

To use this Actor, you pay a monthly rental fee to the developer. The rent is subtracted from your prepaid usage every month after the free trial period.You also pay for the Apify platform usage, which gets cheaper the higher Apify subscription plan you have.

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

## 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

A powerful Apify Actor that scrapes comments from YouTube videos with support for bulk processing, automatic proxy fallback, and comprehensive comment data extraction.

### Why Choose Us?

- **Reliable Scraping**: Automatically handles YouTube's anti-bot measures with intelligent proxy fallback
- **Bulk Processing**: Scrape comments from multiple videos in a single run
- **Comprehensive Data**: Extract all comment details including replies, likes, author info, and more
- **Flexible Configuration**: Customize sort order and comment limits
- **Production Ready**: Built with error handling, retry logic, and detailed logging
- **Smart Proxy Management**: Automatic fallback from no proxy → datacenter → residential proxy with retry logic

### Key Features

- ✅ Scrape comments from YouTube videos by URL or video ID
- ✅ Support for both "top" and "newest" sort orders
- ✅ Automatic proxy fallback (no proxy → datacenter → residential with 3 retries)
- ✅ Extract reply comments with parent-child relationships
- ✅ Get comprehensive comment metadata (likes, replies, author info, etc.)
- ✅ Bulk processing of multiple videos
- ✅ Configurable comment limits
- ✅ Detailed logging for monitoring progress
- ✅ Handles string list input format for easy URL entry

### Input

#### JSON Example

```json
{
  "startUrls": [
    "https://www.youtube.com/watch?v=KrLj6nc516A",
    "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
  ],
  "maxComments": 50,
  "sortOrder": "top",
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}
````

#### Input Fields

- **startUrls** (required): Array of YouTube video URLs or video IDs to scrape
  - Can be full URLs: `"https://www.youtube.com/watch?v=VIDEO_ID"`
  - Or just video IDs: `"VIDEO_ID"`
  - Supports multiple videos for bulk processing
  - Format: Simple string array (e.g., `["url1", "url2"]`)

- **maxComments** (optional, default: 50): Maximum number of comments to scrape per video
  - Set to `0` to scrape all available comments
  - Integer value
  - Default is 50 comments per video

- **sortOrder** (optional, default: "top"): How to sort comments
  - Options: `"top"` for top comments or `"newest"` for newest first
  - Default: `"top"`

- **proxyConfiguration** (optional): Proxy settings
  - By default, no proxy is used (`useApifyProxy: false`)
  - If YouTube blocks requests, the actor automatically falls back to datacenter proxy, then residential proxy
  - The actor will retry up to 3 times with residential proxy if needed
  - Set `useApifyProxy: true` to use Apify proxy from the start
  - Once fallback occurs, the actor sticks with the working proxy for all remaining requests

**Note**: Language and region settings are automatically configured for optimal performance. The actor uses default settings (en-GB language, US region) that work well for most use cases.

### Output

#### JSON Example

```json
{
  "cid": "Ugzxs4_5UJwAI1xrNF14AaABAg",
  "type": "comment",
  "publishedTimeText": "2 years ago",
  "comment": "Subscribe to be in one of my upcoming videos (it's going to be huge!)",
  "author": "@MrBeast",
  "avatar": "https://yt3.ggpht.com/nxYrc_1_2f77DoBadyxMTmv7ZpRZapHR5jbuYe7PlPd5cIRJxtNNEYyOC0ZsxaDyJJzXrnJiuDE=s88-c-k-c0x00ffffff-no-rj",
  "authorIsChannelOwner": true,
  "isVerified": true,
  "voteCount": 189000,
  "hasCreatorHeart": true,
  "replyCount": 763,
  "replyToCid": null,
  "videoId": "KrLj6nc516A",
  "pageUrl": "https://www.youtube.com/watch?v=KrLj6nc516A",
  "title": "$1 vs $100,000,000 Car!",
  "commentsCount": 155000
}
```

#### Output Fields

- **cid**: Unique comment ID
- **type**: Always "comment"
- **publishedTimeText**: Relative time string (e.g., "2 years ago", "3 weeks ago")
- **comment**: The comment text content
- **author**: Author username with @ prefix (e.g., "@MrBeast")
- **avatar**: URL to author's profile picture
- **authorIsChannelOwner**: Boolean indicating if author owns the channel
- **isVerified**: Boolean indicating if author is verified
- **voteCount**: Number of likes/upvotes
- **hasCreatorHeart**: Boolean indicating if creator hearted this comment
- **replyCount**: Number of replies to this comment
- **replyToCid**: Parent comment ID (null for top-level comments, contains parent CID for replies)
- **videoId**: YouTube video ID
- **pageUrl**: Full YouTube video URL
- **title**: Video title
- **commentsCount**: Total number of comments on the video

### 🚀 How to Use the Actor (via Apify Console)

1. Log in at <https://console.apify.com> and go to **Actors**
2. Find your actor (youtube-comments-scraper) and click it
3. Configure inputs:
   - Add YouTube video URLs or IDs in the `startUrls` field (as a simple list of strings)
   - Set `maxComments` (0 for all comments, or any number like 50, 100, etc.)
   - Choose `sortOrder` ("top" or "newest")
   - Configure proxy settings if needed (optional)
4. Click **Start** to run the actor
5. Monitor logs in real time to see progress, including proxy fallback events
6. Access results in the **OUTPUT** tab when scraping completes
7. Export results to JSON or CSV format

### Best Use Cases

- **Content Analysis**: Analyze audience engagement and sentiment from video comments
- **Market Research**: Gather feedback on products or services mentioned in videos
- **Social Media Monitoring**: Track discussions about brands or topics
- **Academic Research**: Collect data for social media studies and analysis
- **Competitor Analysis**: Monitor competitor video engagement and audience feedback
- **Influencer Research**: Analyze comment patterns and audience interaction
- **Trend Analysis**: Track what viewers are saying about trending videos

### Frequently Asked Questions

**Q: How many comments can I scrape?**\
A: You can scrape all available comments by setting `maxComments` to 0, or limit it to a specific number. The default is 50 comments per video.

**Q: Does the actor handle rate limiting?**\
A: Yes, the actor includes automatic retry logic and intelligent proxy fallback to handle rate limits and blocks. It will automatically switch from no proxy → datacenter → residential proxy if needed.

**Q: Can I scrape comments from private videos?**\
A: No, the actor only works with publicly available videos. Private or age-restricted videos cannot be accessed.

**Q: How long does scraping take?**\
A: It depends on the number of comments and videos. Typically, 50 comments take about 30-60 seconds per video. Larger batches may take longer.

**Q: What happens if YouTube blocks the request?**\
A: The actor automatically falls back to datacenter proxy, then residential proxy if needed, with up to 3 retry attempts. All proxy events are logged clearly so you can monitor the process.

**Q: Can I use just video IDs instead of full URLs?**\
A: Yes! You can provide either full YouTube URLs or just the video ID (11 characters). The actor will handle both formats automatically.

**Q: Does the actor scrape reply comments?**\
A: Yes, the actor extracts both top-level comments and their replies, maintaining parent-child relationships through the `replyToCid` field.

**Q: What format should I use for startUrls?**\
A: Use a simple array of strings. For example: `["https://www.youtube.com/watch?v=VIDEO_ID", "VIDEO_ID"]` - both formats work!

### Support and Feedback

For issues, questions, custom solutions, or feature requests, please contact us at:

📧 **Email**: dev.scraperengine@gmail.com

We're here to help and always open to suggestions for improving the actor!

***

### Cautions

- Data is collected only from **publicly available sources**
- No data is taken from private accounts or password-protected content
- The end user is responsible for ensuring legal compliance (spam laws, privacy, data protection, etc.)
- Respect YouTube's Terms of Service and rate limits
- Use the actor responsibly and in accordance with YouTube's usage policies
- The actor includes automatic proxy fallback to minimize blocking, but excessive use may still result in temporary restrictions

# Actor input Schema

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

📋 Enter the YouTube videos you want to scrape comments from. You can use full URLs (e.g. https://www.youtube.com/watch?v=VIDEO\_ID or https://youtu.be/VIDEO\_ID) or just the 11-character video ID. Add multiple URLs or IDs to scrape several videos in one run — the actor processes each video sequentially. Each video's comments are saved to the dataset with the correct video title and metadata.

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

🔢 Set the maximum number of comments to scrape per video. Use 0 for no limit (scrape all available comments). For faster runs or testing, use values like 100, 500, or 1000. The actor stops fetching once this limit is reached for each video. Default is 50.

## `sortOrder` (type: `string`):

⬆️ Choose how comments are ordered when fetching. • top — Shows the most liked and relevant comments first (YouTube's default). Best for sentiment analysis or finding popular opinions. • newest — Shows the most recently posted comments first. Best for monitoring live discussions or recent feedback.

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

🛡️ Configure proxy settings for scraping. By default, no proxy is used. If you encounter rate limits, blocks, or geographic restrictions, enable Apify Proxy. The actor will automatically try datacenter proxies first, then residential proxies if needed. Residential proxies work best for strict regions but cost more. Leave disabled unless you experience blocking.

## Actor input object example

```json
{
  "startUrls": [
    "https://www.youtube.com/watch?v=KrLj6nc516A"
  ],
  "maxComments": 50,
  "sortOrder": "top",
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}
```

# 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 = {
    "startUrls": [
        "https://www.youtube.com/watch?v=KrLj6nc516A"
    ],
    "proxyConfiguration": {
        "useApifyProxy": false
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("scraply/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 = {
    "startUrls": ["https://www.youtube.com/watch?v=KrLj6nc516A"],
    "proxyConfiguration": { "useApifyProxy": False },
}

# Run the Actor and wait for it to finish
run = client.actor("scraply/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 '{
  "startUrls": [
    "https://www.youtube.com/watch?v=KrLj6nc516A"
  ],
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}' |
apify call scraply/youtube-comments-scraper --silent --output-dataset

```

## MCP server setup

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

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Youtube Comments Scraper",
        "version": "0.1",
        "x-build-id": "NN80l0d9PI9MXeJpA"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/scraply~youtube-comments-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-scraply-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/scraply~youtube-comments-scraper/runs": {
            "post": {
                "operationId": "runs-sync-scraply-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/scraply~youtube-comments-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-scraply-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",
                "required": [
                    "startUrls"
                ],
                "properties": {
                    "startUrls": {
                        "title": "🔗 YouTube Video URLs or IDs",
                        "type": "array",
                        "description": "📋 Enter the YouTube videos you want to scrape comments from. You can use full URLs (e.g. https://www.youtube.com/watch?v=VIDEO_ID or https://youtu.be/VIDEO_ID) or just the 11-character video ID. Add multiple URLs or IDs to scrape several videos in one run — the actor processes each video sequentially. Each video's comments are saved to the dataset with the correct video title and metadata.",
                        "items": {
                            "type": "string"
                        }
                    },
                    "maxComments": {
                        "title": "📊 Maximum Comments per Video",
                        "minimum": 0,
                        "type": "integer",
                        "description": "🔢 Set the maximum number of comments to scrape per video. Use 0 for no limit (scrape all available comments). For faster runs or testing, use values like 100, 500, or 1000. The actor stops fetching once this limit is reached for each video. Default is 50.",
                        "default": 50
                    },
                    "sortOrder": {
                        "title": "📑 Comment Sort Order",
                        "enum": [
                            "top",
                            "newest"
                        ],
                        "type": "string",
                        "description": "⬆️ Choose how comments are ordered when fetching. • top — Shows the most liked and relevant comments first (YouTube's default). Best for sentiment analysis or finding popular opinions. • newest — Shows the most recently posted comments first. Best for monitoring live discussions or recent feedback.",
                        "default": "top"
                    },
                    "proxyConfiguration": {
                        "title": "🌐 Proxy Configuration",
                        "type": "object",
                        "description": "🛡️ Configure proxy settings for scraping. By default, no proxy is used. If you encounter rate limits, blocks, or geographic restrictions, enable Apify Proxy. The actor will automatically try datacenter proxies first, then residential proxies if needed. Residential proxies work best for strict regions but cost more. Leave disabled unless you experience blocking."
                    }
                }
            },
            "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
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
