This Python script uses the YouTube Data API v3 to extract top-level comments from all videos on a specific YouTube channel and export them into an Excel file for analysis, research, or reporting.📈🔍
This tool automates:
- ✅ Retrieving all video IDs from a target YouTube channel
- ✅ Extracting top-level comments from each video
- ✅ Handling errors, such as videos with disabled comments
- ✅ Exporting the extracted comments into a structured Excel spreadsheet
Ensure the following Python packages are installed:
pip install google-api-python-client pandas openpyxlYou will also need a valid YouTube Data API v3 Key (see below).
Follow these steps to obtain your API key:
- Go to the Google Cloud Console.
- Sign in using your Google account.
- Click "Create a Project" or select an existing one.
- In the top search bar, type "YouTube Data API v3".
- Select it from the results, then click "Enable".
- In the left sidebar, go to "Credentials".
- Click "Create Credentials" → "API key".
- Copy the generated key and paste it into the script:
API_KEY = "YOUR_API_KEY_HERE"To find the Channel ID of a target YouTube channel:
- Open the YouTube channel in your web browser.
- Click the "About" tab (or "More", depending on your platform).
- Scroll down and click "Share Channel" or look for the Channel ID section.
- Copy the Channel ID shown and paste it into the script where required:
channel_id = "YOUR_CHANNEL_ID"-
Clone or download this repository to your local machine.
-
Open the Python script in your preferred editor.
-
Replace the placeholder values:
DEVELOPER_KEYwith your YouTube API keychannel_idwith the Channel ID of the target channel
-
Run the script using the command:
python your_script_name.py
-
The comments will be saved to an Excel file named:
comments.xlsx
The resulting Excel file includes:
| Column | Description |
|---|---|
author |
Commenter’s display name |
published_at |
Timestamp of original comment |
updated_at |
Last updated timestamp |
like_count |
Number of likes |
text |
Comment content |
- Only top-level comments are collected (replies are excluded).
- The script automatically handles pagination for channels with many videos.
- Videos with disabled comments are gracefully skipped.
- API quota limits may restrict usage — use your key responsibly.
Contributions are welcome!
Feel free to submit a pull request or open an issue to suggest improvements, report bugs, or request new features.