The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Scrape top comments from YouTube

Scraping top comments from YouTube is a common request but it requires careful handling because of YouTube’s terms of service and API usage policies. If you want to collect top comments programmatically, the best way is to use the YouTube Data API which officially supports fetching comments for videos.

Here’s a quick overview of how you can do that:

Using YouTube Data API to get top comments

  1. Get a YouTube Data API key

    • Go to the Google Cloud Console.

    • Create a project and enable the YouTube Data API v3.

    • Generate an API key.

  2. Use the commentThreads endpoint to fetch comments for a video.

Example API request:

http
GET https://www.googleapis.com/youtube/v3/commentThreads?key=YOUR_API_KEY&textFormat=plainText&part=snippet&videoId=VIDEO_ID&maxResults=20&order=relevance
  • videoId — The ID of the YouTube video.

  • order=relevance — To get top (most relevant) comments.

  • maxResults — Number of comments to fetch (up to 100 per request).

Python example to fetch top comments:

python
import requests API_KEY = 'YOUR_API_KEY' VIDEO_ID = 'VIDEO_ID' url = f'https://www.googleapis.com/youtube/v3/commentThreads?key={API_KEY}&textFormat=plainText&part=snippet&videoId={VIDEO_ID}&maxResults=20&order=relevance' response = requests.get(url) data = response.json() for item in data.get('items', []): comment = item['snippet']['topLevelComment']['snippet']['textDisplay'] author = item['snippet']['topLevelComment']['snippet']['authorDisplayName'] print(f'{author}: {comment}n')

If you want me to write you a full script or guide tailored to your needs, just ask! Note that scraping YouTube comments directly by parsing the webpage HTML is against YouTube’s policies and can get blocked, so using the API is the recommended approach.

Would you like me to prepare a detailed tutorial or a ready-to-use script for this?

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About