# Youtube Comment Scraper (`topaz_sharingan/youtube-comment-scraper`)

Introducing the YouTube Comment Scraper — a dynamic tool designed to unlock the wealth of insights hidden within YouTube video comments. Whether you're a content creator, researcher, or simply curious, this actor empowers you to effortlessly extract and analyze valuable information, including commen

- **URL**: https://beta-securitybyobscurity.apify.com/topaz\_sharingan/youtube-comment-scraper.md
- **Developed by:** [Moses Bilal](https://beta-securitybyobscurity.apify.com/topaz_sharingan) (community)
- **Categories:** Social media, SEO tools, Integrations
- **Stats:** 126 total users, 8 monthly users, 93.3% runs succeeded, 6 bookmarks
- **User rating**: No ratings yet

## Pricing

$20.00/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

# README

## YouTube Comment Scraper

### Introduction

**YouTube Comment Scraper** is a powerful tool designed to extract valuable data from YouTube video comments. With this scraper, you can effortlessly gather information such as comment content, author details, reply count, like count, and voting status. Additionally, you can choose to include replies to each comment.

#### Key Features

- Extract YouTube video comments with ease.
- Retrieve essential comment details, including author information, reply count, and likes.
- Option to include all replies to each comment.
- Configurable to limit the maximum number of comments to scrape.

#### Typical Use Cases

- **Audience Engagement Analysis**: Analyze the engagement and sentiment of comments on a specific YouTube video.
- **Content Improvement**: Gain insights from user feedback to enhance video content.
- **Competitor Analysis**: Monitor and analyze comments on competitors' videos.

### Inputs

#### Data Input

The scraper takes the following inputs:

- **Start URLs**: The URLs of the YouTube videos for which you want to scrape comments.
- **Maximum Comment Count**: The maximum number of comments to scrape for each video.

#### Input Example

```json
{
    "startUrls": ["https://www.youtube.com/watch?v=ySA7mSgF54I"],
    "maxCommentCount": 30,
    "get_all_comments": false
}
```

## Outputs

The scraper produces the following output for each comment:

- **Comment Author**: The username of the comment author.
- **Author's Thumbnail**: The URL of the author's profile thumbnail.
- **Comment Content**: The content of the comment.
- **Reply Count**: The number of replies to the comment.
- **Comment ID**: The unique ID of the comment.
- **Comment Like Count**: The number of likes on the comment.
- **Time Posted**: The time when the comment was posted.

### Output Example

```json
{
    "content": "The best country artist in a very long time to me",
    "author": "@Allman2013",
    "commentId": "UgwYXDX8ILkTIytauQR4AaABAg",
    "publishedTime": "4 months ago",
    "thumbnail": "https://yt3.ggpht.com/ytc/AIdro_ldjGNNBkVwkJPi3uO9izWA4BI69xAM2IlNxZV3vZIJL0qd=s88-c-k-c0x00ffffff-no-rj",
    "channelId": "UCN7Ypfqdsh4ieWUvCXcneWw",
    "isVerified": false,
    "likeCount": "14 likes",
    "replyCount": "0 replies"
}
```

## Usage

### How to Run the Scraper

1. Go to [Apify](https://apify.com) and log in or create an account if you don't have one.
2. Create a new task and select the "YouTube Comment Scraper" scraper.
3. Configure the scraper's input settings by providing the YouTube video URLs and specifying the maximum number of comments to scrape.
4. (Optional) Set the "Include All Replies" input according to your preference.
5. Start the task and wait for it to complete.
6. Once the task is finished, you can access the scraped data in the task's dataset.

### How to Interpret the Scraper's Results

The scraper will provide you with a JSON dataset containing the scraped YouTube video comments data. Each comment will have its own set of properties, as described in the "Outputs" section.

#### Examples

##### Example 1: Scraping a Specific Number of Comments.

In this example, we will scrape comments from a YouTube video, including all replies to each comment.

```json
{
    "startUrls": ["https://www.youtube.com/watch?v=example_video_id"],
    "maxCommentCount": 30,
    "get_all_comments": false
}
```

##### Example 2: Scraping all Comments

In this example, we will scrape comments from a YouTube video, excluding replies.

```json
{
    "startUrls": ["https://www.youtube.com/watch?v=example_video_id"],
    "maxCommentCount": 30,
    "get_all_comments": true
}
```

## Troubleshooting

### Common Problems and Solutions

#### Problem: The scraper is not returning any data.

##### Solution:

Ensure that the provided video URLs are correct, and the videos have comments available.

#### Problem: Rate limiting issues.

##### Solution:

If you encounter rate limiting issues, try adjusting the scraping speed or contact Apify support for assistance.

## Additional Information

### Links to Related Resources

- [Apify](https://apify.com)
- [Apify Documentation](https://apify.com/docs)

### Acknowledgements

This scraper is powered by Apify, a leading web scraping and automation platform. Special thanks to the Apify team for their contributions.

# Actor input Schema

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

Url to start with.

## `maxCommentCount` (type: `integer`):

Maximum number of requests at a time

## `get_all_comments` (type: `boolean`):

if you want to get all comments? ✨ Toggle (Get all comments) to see them! Just a heads up: Fetching and processing all comments may take a moment, so comments will appear once they're ready. ✨ We'll let you know when they're ready! Thanks for your patience!

## Actor input object example

```json
{
  "startUrls": [
    "https://www.youtube.com/watch?v=ySA7mSgF54I"
  ],
  "maxCommentCount": 10,
  "get_all_comments": 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=ySA7mSgF54I"
    ],
    "maxCommentCount": 10
};

// Run the Actor and wait for it to finish
const run = await client.actor("topaz_sharingan/youtube-comment-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=ySA7mSgF54I"],
    "maxCommentCount": 10,
}

# Run the Actor and wait for it to finish
run = client.actor("topaz_sharingan/youtube-comment-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=ySA7mSgF54I"
  ],
  "maxCommentCount": 10
}' |
apify call topaz_sharingan/youtube-comment-scraper --silent --output-dataset

```

## MCP server setup

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

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Youtube Comment Scraper",
        "description": "Introducing the YouTube Comment Scraper — a dynamic tool designed to unlock the wealth of insights hidden within YouTube video comments. Whether you're a content creator, researcher, or simply curious, this actor empowers you to effortlessly extract and analyze valuable information, including commen",
        "version": "0.0",
        "x-build-id": "1gztppcjFSKV68Q5f"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/topaz_sharingan~youtube-comment-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-topaz_sharingan-youtube-comment-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/topaz_sharingan~youtube-comment-scraper/runs": {
            "post": {
                "operationId": "runs-sync-topaz_sharingan-youtube-comment-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/topaz_sharingan~youtube-comment-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-topaz_sharingan-youtube-comment-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": {
                    "startUrls": {
                        "title": "Channel Name/Url",
                        "type": "array",
                        "description": "Url to start with.",
                        "items": {
                            "type": "string"
                        }
                    },
                    "maxCommentCount": {
                        "title": "Maximum number of comments",
                        "type": "integer",
                        "description": "Maximum number of requests at a time"
                    },
                    "get_all_comments": {
                        "title": "Get all comments",
                        "type": "boolean",
                        "description": "if you want to get all comments? ✨ Toggle (Get all comments) to see them! Just a heads up: Fetching and processing all comments may take a moment, so comments will appear once they're ready. ✨ We'll let you know when they're ready! Thanks for your patience!",
                        "default": false
                    }
                }
            },
            "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
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
