YouTube - Retrieve Video Comments

Get plain text:

curl -H "Accept: text/plain" https://jugoya.ai/guides/youtube/video-comments

Overview

Extract comments from YouTube videos using browser automation. Comments are loaded dynamically and require scrolling to load more.

Prerequisites

  • Logged into YouTube (optional, but may affect visible comments)
  • Video URL or navigation to video page

Workflow

Step 1: Navigate to Video

Navigate to the target video URL or click on a video thumbnail from search/home.

Step 2: Scroll to Comments Section

Comments are below the video player. The comments section header shows:

  • "X Comments" - total comment count
  • button "Sort comments" - sorting options (Top/Newest)

Step 3: Capture Comments from Snapshot

Take a browser snapshot. Comments appear with this structure:

button "@username"
link "@username"
link "X minutes ago" or "X hours ago"
[Comment text appears here]
link "Like this comment along with X other people"
link "Dislike this comment"
link "Reply"
button "Action menu"

Key Elements

ElementPurpose
button "Sort comments"Change sort order (Top comments / Newest first)
link "@username"Commenter's channel
link "X minutes ago"Comment timestamp
link "Like this comment..."Like count indicator
link "Reply"View/add replies
input "" (in comments area)Add your own comment

Loading More Comments

Comments load dynamically on scroll. To load more:

  1. Use browser_evaluate with scroll command
  2. Or click on button "Show more replies" for threaded comments
  3. Take new snapshot after scrolling

Extracting Comment Data

From snapshot, parse each comment block:

  • Username: @username link text
  • Time: relative timestamp link
  • Content: text between timestamp and "Like this comment" link
  • Likes: number in "Like this comment along with X other people"

Tips

  • Live stream comments may have "Live chat replay" instead of regular comments
  • Some videos have comments disabled - check for "Comments are turned off" message
  • Pinned comments appear first with a pin indicator

Limitations

  • Cannot access comments on age-restricted videos without login
  • Comment count may differ from visible comments (deleted/hidden comments)
  • Very long comment threads require multiple scroll+snapshot cycles