# Youtube Comment Scraper (`neuro-scraper/youtube-comments-scraper`)

\*\* Cheapest YouTube Comment Scraper\*\*! 🎥
Turn comments 💬 into insights 🧠 for **research, marketing, and sentiment analysis** 📊.
Fast ⚡, accurate 🎯, and effortless — your shortcut to understanding real emotions behind every video 🚀.

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

## Pricing

$0.40 / 1,000 results

This Actor is paid per result. You are not charged for the Apify platform usage, but only a fixed price for dataset items the Actor outputs.

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

# README

***

## FILE: README.md

***

## 🌟 YouTube Comment Scraper

> ⚡ Instant audience insights — collect, analyze, and export YouTube comments with zero friction.

***

### 📖 Summary

A production-ready Apify Actor that extracts structured YouTube comments quickly and reliably. Ideal for research, marketing, sentiment analysis, and trend detection — plug-and-play in Apify Console.

***

### 💡 Use cases / When to use

- Research & academic analysis (qualitative + quantitative).
- Sentiment analysis and brand monitoring.
- Creator & community engagement insights.
- Training data collection for NLP models.

***

### ⚡ Quick Start (Console — one click)

1. Open this Actor in Apify Console.
2. Paste your YouTube video URL(s) into `startUrls`.
3. Click **Run** — results appear in the default dataset in seconds.

***

### ⚙️ Quick Start (CLI & API)

**CLI**

```bash
apify run -p input.json
```

**Python (apify-client)**

```python
from apify_client import ApifyClient
client = ApifyClient('<APIFY_TOKEN>')
run = client.actor('your-actor-id').call(run_input={
    'startUrls': ['https://www.youtube.com/watch?v=abcd1234'],
    'maxComments': 100,
    'getAllComments': False,
    'sortBy': 'top'
})
print('Dataset ID:', run['defaultDatasetId'])
```

***

### 📝 Inputs (fields & schema highlights)

Always use JSON input for Console / CLI / API.

- `startUrls` (array | required) — List of YouTube video URLs or objects with `url` fields.
- `maxComments` (integer | optional) — Max comments per video (use with `getAllComments=false`).
- `getAllComments` (boolean | optional) — When true, fetches all available comments.
- `sortBy` (string | optional) — `top`, `newest`, or `oldest`.
- `proxyConfig` (object | optional) — Proxy settings (e.g., `{ "useApifyProxy": true }`).

***

### ⚙️ Configuration (Quick reference)

|        🔑 Name | 📝 Type |  ❓ Required | ⚙️ Default |                                        📌 Example                                        |                    🧠 Notes                    |
| -------------: | :-----: | :---------: | :--------: | :--------------------------------------------------------------------------------------: | :--------------------------------------------: |
|      startUrls |  array  |    ✅ Yes    |    null    | \["<https://www.youtube.com/watch?v=abcd1234>"] |            Primary input — required.           |
|    maxComments | integer |     ❌ No    |    null    |                                            200                                           | Limits results when `getAllComments` is false. |
| getAllComments | boolean |     ❌ No    |    false   |                                           true                                           |             Toggle full extraction.            |
|         sortBy |  string |     ❌ No    |    "top"   |                                         "newest"                                         |               Sorting preference.              |
|    proxyConfig |  object | ⚙️ Optional |     {}     |                                  {"useApifyProxy": true}                                 |     Proxy options for network reliability.     |

**Console mini-example**: Paste this into Input and click Run

```json
{ "startUrls": ["https://www.youtube.com/watch?v=abcd1234"], "maxComments": 50 }
```

***

### 📄 Outputs (dataset / KV examples)

Each dataset item represents one comment with structured fields.

**Example output item:**

```json
{
  "cid": "Ugxyz123abc",
  "author": "Jane Doe",
  "text": "Great tutorial — helped me a lot!",
  "votes": 124,
  "time_text": "2 days ago",
  "time_unix": 1716239023,
  "video_id": "abcd1234",
  "video_url": "https://www.youtube.com/watch?v=abcd1234",
  "total_available_comments": 523
}
```

***

### 🔑 Environment Variables

Use placeholders for secrets.

- `APIFY_TOKEN`: `<APIFY_TOKEN>` — required for API/CLI runs.
- `HTTP_PROXY`: `http://<PROXY_USER:PASS@HOST:PORT>` — optional.
- `HTTPS_PROXY`: `https://<PROXY_USER:PASS@HOST:PORT>` — optional.

***

### ▶️ How to Run (step-by-step)

1. **Console** — Paste JSON input and click **Run**. Results in default dataset.
2. **CLI** — `apify run -p input.json`.
3. **API** — Use `apify-client` to call the actor; fetch `defaultDatasetId` for results.

***

### ⏰ Scheduling & Webhooks

- Use Apify **Schedules** to run automatically (hourly/daily).
- Attach **Webhooks** to trigger downstream processes (e.g., downstream ML or dashboards).

***

### 🕾️ Logs & Troubleshooting

**Common messages & quick fixes**

- `No startUrls provided` — Add valid YouTube URLs in `startUrls`.
- Empty output → video may be private or comments disabled.
- Rate-limiting / network errors → enable `proxyConfig` or Apify Proxy.

***

### 🔒 Permissions & Storage notes

- Outputs are stored in the Apify **default dataset**.
- No personal credentials are stored in plaintext — always use secrets.
- Privacy-safe: collects public comments only; follow YouTube terms of service.

***

### 🔟 Changelog / Versioning tip

- v1.0 — Initial production-ready release.
- Versioning tip: bump major for breaking changes to input schema.

***

### 🖌 Notes / TODOs

- TODO: Consider proxy rotation for large-scale scraping — main.py performs network calls.
- TODO: Add optional post-processing hooks (e.g., sentiment flag) — non-breaking enhancement.

***

### 🌍 Proxy Configuration

If you encounter network issues or rate limits, enable Apify Proxy or set custom proxies.

**Enable Apify Proxy (Console)** — toggle `proxyConfig.useApifyProxy` to `true`.

**Custom proxy example**

```json
{ "proxyConfig": { "proxyUrls": ["http://<PROXY_USER:PASS@HOST:PORT"] } }
```

**Env vars**

```
HTTP_PROXY=http://<PROXY_USER:PASS@HOST:PORT>
HTTPS_PROXY=https://<PROXY_USER:PASS@HOST:PORT>
```

Remember to store credentials as **Apify secrets**, not in plain input.
`TODO: Consider proxy rotation for large-scale scraping.`

***

### 📚 References

- Apify Actor README Guidelines — official docs.
- Input/Output schema — official docs.
- Apify CLI & API docs — official docs.

***

### 🤔 What I inferred from main.py

- Actor extracts YouTube comments from provided video URLs.
- Supports `maxComments`, `getAllComments`, and `sortBy` inputs.
- Async architecture for efficient fetching.
- Network activity detected → Proxy guidance included.

***

> Run this Actor on Apify Console — get instant results in seconds.

***

## FILE: input.example.json

***

{
"startUrls": \[
"<https://www.youtube.com/watch?v=abcd1234>",
"<https://youtu.be/wxyz5678>"
],
"maxComments": 100,
"getAllComments": false,
"sortBy": "top",
"proxyConfig": { "useApifyProxy": true }
}

***

## FILE: CONFIG.md

***

## CONFIG.md — Quick configuration & tips

### Purpose

Small reference for operators deploying this actor at scale.

### Important notes

- Input schema expects `startUrls` (array). Supports both full YouTube links and shortened `youtu.be` links.
- For large runs, set `getAllComments` to `true` and consider using Apify Proxy.
- Keep `maxComments` if you want a controlled result set for sampling.

### Troubleshooting tips

- If dataset is empty, verify the video is public and has comments enabled.
- Use `maxComments` to reduce runtime and avoid transient rate limits.

### Security

- Always keep `APIFY_TOKEN` and proxy credentials in Apify secrets.
- Do not store sensitive credentials in input JSON.

***

*End of saved files.*

# Actor input Schema

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

Enter one or multiple YouTube video or channel URLs from which to extract comments.

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

Set the maximum number of comments to retrieve per video. Leave empty to fetch all available comments for a complete dataset.

## `getAllComments` (type: `boolean`):

When enabled, the scraper collects every single comment without respecting the limit. Use this for full comment extraction.

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

Select the order in which comments should be returned. 'top' retrieves the most liked and engaged comments first, 'latest' fetches newest comments first, and 'oldest' fetches the oldest comments first.

## Actor input object example

```json
{
  "startUrls": [
    {
      "url": "https://www.youtube.com/watch?v=k_dYs8ovmnk"
    },
    {
      "url": "https://www.youtube.com/watch?v=VegKhno-BK8"
    }
  ],
  "maxComments": 100,
  "getAllComments": false,
  "sortBy": "top"
}
```

# 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": [
        {
            "url": "https://www.youtube.com/watch?v=k_dYs8ovmnk"
        },
        {
            "url": "https://www.youtube.com/watch?v=VegKhno-BK8"
        }
    ],
    "maxComments": 100
};

// Run the Actor and wait for it to finish
const run = await client.actor("neuro-scraper/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": [
        { "url": "https://www.youtube.com/watch?v=k_dYs8ovmnk" },
        { "url": "https://www.youtube.com/watch?v=VegKhno-BK8" },
    ],
    "maxComments": 100,
}

# Run the Actor and wait for it to finish
run = client.actor("neuro-scraper/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": [
    {
      "url": "https://www.youtube.com/watch?v=k_dYs8ovmnk"
    },
    {
      "url": "https://www.youtube.com/watch?v=VegKhno-BK8"
    }
  ],
  "maxComments": 100
}' |
apify call neuro-scraper/youtube-comments-scraper --silent --output-dataset

```

## MCP server setup

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

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Youtube Comment Scraper",
        "description": "** Cheapest YouTube Comment Scraper**! 🎥\nTurn comments 💬 into insights 🧠 for **research, marketing, and sentiment analysis** 📊.\nFast ⚡, accurate 🎯, and effortless — your shortcut to understanding real emotions behind every video 🚀.",
        "version": "0.0",
        "x-build-id": "vaAI1wgPNxLkj4ldQ"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/neuro-scraper~youtube-comments-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-neuro-scraper-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/neuro-scraper~youtube-comments-scraper/runs": {
            "post": {
                "operationId": "runs-sync-neuro-scraper-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/neuro-scraper~youtube-comments-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-neuro-scraper-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": "Video URLs",
                        "type": "array",
                        "description": "Enter one or multiple YouTube video or channel URLs from which to extract comments.",
                        "items": {
                            "type": "object",
                            "required": [
                                "url"
                            ],
                            "properties": {
                                "url": {
                                    "type": "string",
                                    "title": "URL of a web page",
                                    "format": "uri"
                                }
                            }
                        }
                    },
                    "maxComments": {
                        "title": "Comment Limit",
                        "type": "integer",
                        "description": "Set the maximum number of comments to retrieve per video. Leave empty to fetch all available comments for a complete dataset."
                    },
                    "getAllComments": {
                        "title": "Retrieve All Comments",
                        "type": "boolean",
                        "description": "When enabled, the scraper collects every single comment without respecting the limit. Use this for full comment extraction.",
                        "default": false
                    },
                    "sortBy": {
                        "title": "Comment Sorting Preference",
                        "enum": [
                            "top",
                            "latest",
                            "oldest"
                        ],
                        "type": "string",
                        "description": "Select the order in which comments should be returned. 'top' retrieves the most liked and engaged comments first, 'latest' fetches newest comments first, and 'oldest' fetches the oldest comments first.",
                        "default": "top"
                    }
                }
            },
            "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
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
