← All posts

How to Scrape YouTube Data (Use the YouTube Data API)

Quick answer: For almost everyone, the right way to get YouTube data is the official YouTube Data API, not an HTML scraper. It returns video, channel, playlist, and comment metadata as clean JSON, it is free within a generous daily quota, and it keeps you inside Google's terms. Scraping YouTube's pages instead generally violates the Terms of Service, breaks whenever the site changes, and is rarely necessary. Reach for the API first.

YouTube data (view counts, titles, publish dates, channel stats, comment threads) powers research, dashboards, and content analysis. The good news is that YouTube, unlike some platforms, offers a genuinely capable official API. So the compliant path is also the easy path here, which is a rare and welcome thing.

Start with the YouTube Data API

The YouTube Data API (v3) is the sanctioned way to read most of what you would otherwise be tempted to scrape. You create a project in the Google Cloud Console, enable the API, and get an API key (for public data) or set up OAuth (for user-specific or write actions).

What it returns:

  • Videos: title, description, publish date, duration, view count, like count, comment count, tags, thumbnails.
  • Channels: title, description, subscriber count, total views, upload playlist.
  • Playlists and playlist items: ordering and the videos they contain.
  • Search: query across videos, channels, and playlists.
  • Comments and comment threads: top-level comments and replies, where enabled.

Because responses are structured JSON, you never parse a page. You ask for the parts you want and get typed fields back.

API vs scraping the HTML

YouTube Data API Scraping HTML
Terms of service Sanctioned path Generally prohibited
Data format Structured JSON Markup and embedded JSON to parse
Stability Versioned, documented Breaks on layout changes
Rate limits Clear daily quota Undocumented, blocking
Auth API key or OAuth None (until blocked)
Cost Free within quota Hidden cost of maintenance and risk

For the overwhelming majority of projects, the API wins outright. It is free, structured, and supported.

How quotas work, in concept

The API uses a daily quota system rather than a simple request count. Each project gets a quota budget per day, and different operations cost different amounts of quota. Read operations are cheap; a search call costs considerably more; write operations cost the most. You do not pay per request in dollars within the default quota, you spend from your daily allotment.

The practical implications:

  • Design queries to be specific so you are not burning quota on broad searches you then filter client-side.
  • Cache results you will reuse rather than re-fetching.
  • Request a quota increase through Google if a legitimate project needs more, rather than working around limits.

I am deliberately not quoting exact quota numbers, because Google adjusts them; check the current figures in the API documentation.

A code sketch

A minimal call to fetch a video's metadata (public data, API key auth):

import requests

API_KEY = "YOUR_API_KEY"
VIDEO_ID = "dQw4w9WgXcQ"

resp = requests.get(
    "https://www.googleapis.com/youtube/v3/videos",
    params={
        "part": "snippet,statistics",
        "id": VIDEO_ID,
        "key": API_KEY,
    },
    timeout=30,
)
resp.raise_for_status()
item = resp.json()["items"][0]

print(item["snippet"]["title"])
print(item["snippet"]["channelTitle"])
print(item["statistics"]["viewCount"])

That is the whole thing. No headless browser, no proxy rotation, no fragile selectors. Swap videos for channels, search, or commentThreads and adjust part to get other resources.

When scraping public pages is and is not appropriate

There are narrow cases the API does not cover: full transcripts in some situations, certain fields that are on-page but not exposed via the API, or a one-off read of a single public page. If you find yourself there, a few honest principles:

  • Confirm the API truly cannot serve the need before scraping anything.
  • Only touch public pages you can view without logging in, and respect robots.txt and rate limits.
  • Never bypass sign-in, age gates, or anti-bot systems. Those are access controls, and getting past them is where compliant scraping ends.
  • Do not download or redistribute video content; that is a copyright and ToS matter entirely separate from reading metadata.

For fetching a single public page you are entitled to read, link.sc returns clean markdown or JSON in one call:

curl https://link.sc/v1/fetch \
  -H "Authorization: Bearer lsc_..." \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://www.example.com/public-article",
    "format": "markdown"
  }'

Use link.sc for the legitimate slice: public pages you can access and official API responses. It is not a tool for defeating YouTube's defenses, and you should not use any tool that way.

The legal and ethics note

YouTube's Terms of Service prohibit accessing content through anything other than the API or the interface as provided, and specifically prohibit automated scraping of the site. Google's API Services Terms govern how you use API data. If you collect comments, you are handling personal data, which brings the GDPR and similar laws into scope. And video content itself is copyrighted; reading metadata is one thing, copying the media is another.

Guardrails:

  • Use the YouTube Data API for video, channel, and comment metadata.
  • Stay within quota; request an increase rather than evading limits.
  • Do not scrape logged-in or gated content, and do not bypass access controls.
  • Handle comment data lawfully if you store anything tied to a person.

For the wider picture, see is web scraping legal and ethical web scraping and compliance best practices. None of this is legal advice.

The bottom line

YouTube is the happy case: the official API is capable enough that most people never need to scrape a page, and using it is both the compliant path and the simpler one. Enable the YouTube Data API, design around the quota, cache what you reuse, and reserve any public-page fetching for the rare field the API genuinely does not expose. That keeps your pipeline stable, free, and inside the rules.


Need clean content from public pages and API responses in one call? link.sc fetches any public URL to markdown or JSON. Try it free.