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

YouTube comment scraper is a powerful tool that extracts valuable data from any YouTube video's comment section. Gather all comments, authors, posting dates, votes, reply counts. Use CSV or Excel or HTML tables, JSON...

- **URL**: https://beta-securitybyobscurity.apify.com/karamelo/youtube-comments-scraper.md
- **Developed by:** [karamelo](https://beta-securitybyobscurity.apify.com/karamelo) (community)
- **Categories:** Videos, Social media
- **Stats:** 54 total users, 3 monthly users, 100.0% runs succeeded, 3 bookmarks
- **User rating**: No ratings yet

## Pricing

$12.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 Scraping: Blazing fast

### Unlocking Audience Insights: A Deep Dive into YouTube Comment Scraping 🕵️‍♀️🔎

Understanding your audience is paramount. For content creators, marketers, and businesses leveraging YouTube, the comment section offers a goldmine of valuable insights 💰. But manually sifting through thousands of comments?  😩 That's where the power of **YouTube Comment Scraping** comes in 💪.

#### Unveiling the Power of YouTube Comment Scraping ✨

Imagine effortlessly gathering and analyzing comments from any YouTube video 📺. That's precisely what a **YouTube Comment Scraper** empowers you to do. This powerful tool acts as your digital assistant, efficiently extracting a treasure trove of data 🗃️, including:

- **Every Single Comment:** Capture the complete conversation surrounding a video, no matter how extensive 💬.
- **Detailed Comment Data:** Go beyond just the text. Extract author names, posting dates, comment vote counts, comment reply counts.
- **Effortless Data Organization:** Receive your data neatly packaged in your preferred format – be it JSON, XML, CSV, Excel, or HTML 🗂️.

#### Demystifying the Process: How to Scrape YouTube Comments 🤔➡️✅

You don't need to be a tech whiz to harness the power of YouTube Comment Scraping. The process is surprisingly simple and accessible, even for beginners 👶:

1. **Access the YouTube Comment Scraper:** Select the pre-built scraper designed specifically for extracting YouTube comments ⛏️.
2. **Input Your Targets video link:** Simply provide the URLs of the YouTube videos you want to analyze. 📃
3. **Input Number of comments to scrape:** a 100 in ~30 seconds or a 1000 in ~5 minutes or so, and even 10000 comments and more. 📃
4. **Choose sorting type:** You can sort by Top comments or Newest comments first (default is: top comments first).
5. **Initiate the Scrape:** With a click of a button, set the scraper in motion and let it work its magic ✨.
6. **Download Your Data:** Once the scraping is complete, download the extracted data in your chosen format, ready for analysis 🎉.

#### Transforming Data into Actionable Insights: The Benefits 🚀

But what can you actually *do* with all this valuable comment data? The possibilities are vast:

- **Gauge Audience Sentiment:** Employ sentiment analysis techniques to understand the overall emotional tone towards your videos or specific topics 🤔. Are viewers happy 😊, frustrated 😠, or intrigued 🤔?
- **Uncover Trending Conversations:** Track the frequency of specific keywords or phrases to identify emerging trends and hot topics within your niche 🔥.
- **Measure User Engagement:** Analyze comment volume, replies, and votes to gain a deeper understanding of which videos or themes resonate most with your audience 📈.
- **Enhance Content Strategy:** Leverage user feedback and suggestions gleaned from comments to refine your content strategy, improve video topics, and cater to audience preferences 💡.
- **Conduct Market Research:** Gain insights into your target audience's interests, demographics, and preferences, allowing for more targeted marketing campaigns and content creation 🎯.

#### Navigating the Ethical Landscape: Scraping Responsibly ⚖️

While YouTube Comment Scraping is a powerful tool, it's crucial to utilize it ethically and responsibly. Always prioritize user privacy and adhere to platform terms of service:

- **Focus on Public Data:** Only extract information that users have willingly shared publicly on YouTube 🔓.
- **Respect Privacy Concerns:** Avoid scraping or utilizing any personal data that could potentially identify individuals without their explicit consent ⛔.
- **Review Platform Guidelines:** Familiarize yourself with YouTube's terms of service and scraping policies to ensure compliance ✅.

By approaching YouTube Comment Scraping with an ethical and responsible mindset, you can unlock valuable audience insights while respecting user privacy and fostering a positive online environment 🤝🌎.

**Change log:**

- **06/07/24**
- **-** Added select sorting by top or newest comments.
- **-** Added hasHeart for hearted comments by the video creator.
- **-** Added video details and creator details.
- **-** Bug fixes and better error handling.
- **-** Added more runtime logs for clarity.

# Actor input Schema

## `url` (type: `string`):

The URL of the video you want to extract the comments from.

## `number` (type: `integer`):

How many comments do you want to extract from the video comment section.

## `sorting` (type: `string`):

You can sort the comments by Top Comments first or by Newest comments first.

## Actor input object example

```json
{
  "url": "https://www.youtube.com/watch?v=HXJx8j7JpKY",
  "number": 100,
  "sorting": "Top comments first"
}
```

# 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 = {
    "url": "https://www.youtube.com/watch?v=HXJx8j7JpKY",
    "number": 100,
    "sorting": "Top comments first"
};

// Run the Actor and wait for it to finish
const run = await client.actor("karamelo/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 = {
    "url": "https://www.youtube.com/watch?v=HXJx8j7JpKY",
    "number": 100,
    "sorting": "Top comments first",
}

# Run the Actor and wait for it to finish
run = client.actor("karamelo/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 '{
  "url": "https://www.youtube.com/watch?v=HXJx8j7JpKY",
  "number": 100,
  "sorting": "Top comments first"
}' |
apify call karamelo/youtube-comments-scraper --silent --output-dataset

```

## MCP server setup

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

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "YouTube Comments Scraper",
        "description": "YouTube comment scraper is a powerful tool that extracts valuable data from any YouTube video's comment section. Gather all comments, authors, posting dates, votes, reply counts. Use CSV or Excel or HTML tables, JSON...",
        "version": "0.0",
        "x-build-id": "2utRHdkI9FIfD7MxW"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/karamelo~youtube-comments-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-karamelo-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/karamelo~youtube-comments-scraper/runs": {
            "post": {
                "operationId": "runs-sync-karamelo-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/karamelo~youtube-comments-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-karamelo-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": [
                    "url",
                    "number"
                ],
                "properties": {
                    "url": {
                        "title": "URL of the video you want to extract the comments from.",
                        "type": "string",
                        "description": "The URL of the video you want to extract the comments from."
                    },
                    "number": {
                        "title": "Number of comments",
                        "type": "integer",
                        "description": "How many comments do you want to extract from the video comment section."
                    },
                    "sorting": {
                        "title": "Sort by Top or Newest comments",
                        "enum": [
                            "Top comments first",
                            "Newest comments first"
                        ],
                        "type": "string",
                        "description": "You can sort the comments by Top Comments first or by Newest comments first."
                    }
                }
            },
            "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
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
