20 % off all paid plans with code

Python · YouTube

How to scrape YouTube with Python

Scraping YouTube with a browser means scrolling infinite lists, waiting for scripts and parsing markup that changes often. The official YouTube Data API needs a Google Cloud project and rations requests with a daily quota. This guide takes a third route: you scrape YouTube with Python by calling the everydata.io API, which reads the public YouTube pages and returns them as JSON.

You build three small scripts: a YouTube scraper for search results that pages through the results and saves them to CSV, one that lists the latest videos of a channel, and one that fetches the full details of a video – views, likes, comment count, publish date, duration, category and tags.

Updated · by everydata.io

What you will have at the end

  • A Python script that scrapes YouTube search results for any query into videos.csv.
  • The latest videos of any channel by channel ID, handle URL or channel URL.
  • Full video details by video ID, with a reusable helper that handles rate limits and retries.

What you need

  • Python 3.10 or newer and the requests package (pip install requests).
  • A free everydata.io API key – create one here.
  • A search query, a channel or a video you want to scrape.

01Why scrape YouTube through an API?

YouTube builds its pages with JavaScript and loads more results as you scroll, so a plain HTTP request gets little usable data and a headless browser has to scroll, wait and parse. The everydata.io YouTube API does that work on the server: each call returns one page of results, with a cursor for the next one.

Compared with the official YouTube Data API there is no OAuth screen, no Google Cloud project and no daily unit quota – only your everydata.io key. Every call is one request on your plan, and answers with a 5xx status are not counted.

02Write a small request helper

Put your key into the environment (export EVERYDATA_API_KEY="ds_your_key") and save this helper as everydata.py. It waits when you send too many requests at once (status 429, the answer says how many seconds) and retries a page that failed to load (5xx) once.

everydata.py
import os
import re
import time

import requests

API = "https://api.everydata.io"
KEY = os.environ["EVERYDATA_API_KEY"]


def api_get(path: str, params: dict) -> dict:
    """GET an everydata.io endpoint. Waits when rate limited (429) and retries a failed page load (5xx) once."""
    retried = False
    for _ in range(4):
        resp = requests.get(f"{API}{path}", params=params, headers={"x-api-key": KEY}, timeout=60)
        if resp.status_code == 429:
            wait = re.search(r"in (\d+) seconds", resp.text)
            time.sleep(int(wait.group(1)) + 1 if wait else 60)
            continue
        if resp.status_code >= 500 and not retried:
            retried = True  # 5xx answers are not counted against your quota
            time.sleep(10)
            continue
        resp.raise_for_status()
        return resp.json()
    raise RuntimeError("still rate limited after several waits – try again later")

04Scrape the videos of a YouTube channel

For one channel, pass its channel ID, its handle URL (https://www.youtube.com/@WWE) or its channel URL as id. filter picks the tab: videos_latest (default), streams_latest, shorts_latest or live_now. Page further with cursor, as in the search script.

channel_videos.py
from everydata import api_get

data = api_get("/ytb/youtube-channel-videos", {"id": "https://www.youtube.com/@WWE", "filter": "videos_latest"})
for item in data["items"]:
    print(item["videoId"], item["viewCount"], item["publishedTimeText"], item["title"])
next_page = data["cursor"]  # pass as cursor=... for the next page
Example response · GET /ytb/youtube-channel-videos
{
  "responseStatus": "PAGE_FOUND",
  "responseMessage": "Page successfully found!",
  "channelId": "UCJ5v_MCY6GNUBTO8-D3XoAg",
  "filter": "videos_latest",
  "items": [
    {
      "type": "video",
      "videoId": "b7kl_pcHa0A",
      "title": "Blake Monroe vows to get payback against Giulia: SmackDown exclusive, Sept. 18, 2026",
      "viewCount": 6800,
      "viewCountText": "6.8K views",
      "publishedTimeText": "47 minutes ago",
      "duration": 110,
      "durationText": "1:50"
    }
  ]
}

05Scrape YouTube video details

Search and channel lists give you video IDs. For the full record of one video – exact view, like and comment counts, publish date, category, tags and more – call the video details endpoint with the ID or the video URL.

video_details.py
from everydata import api_get

v = api_get("/ytb/youtube-video-details", {"id": "kJQP7kiw5Fk"})
print(v["title"], "by", v["channelName"])
print(v["viewCount"], "views,", v["likeCount"], "likes,", v["commentCount"], "comments")
print("published", v["publishedAt"], "| duration", v["durationText"], "| category", v["category"])
print("tags:", ", ".join(v["tags"]))
Example response · GET /ytb/youtube-video-details
{
  "responseStatus": "PAGE_FOUND",
  "responseMessage": "Page successfully found!",
  "videoId": "kJQP7kiw5Fk",
  "title": "Luis Fonsi - Despacito ft. Daddy Yankee",
  "channelName": "LuisFonsiVEVO",
  "viewCount": 9125159593,
  "likeCount": 56673581,
  "commentCount": 4300000,
  "publishedAt": "2017-01-12T21:00:02-08:00",
  "duration": 282,
  "durationText": "4:42",
  "category": "Music",
  "tags": [
    "Calypso",
    "Despacito"
  ]
}

To track these numbers over time, the YouTube video stats guide saves them on a schedule. For the comment section of a video, see the YouTube comments API.

06Costs and limits of scraping YouTube

  • Every search page, channel page and video lookup is one request. Three search pages plus details for 20 videos are 23 requests; the free plan includes 100 requests a month.
  • Results follow languageCode and countryCode, like YouTube does for a visitor from that country.
  • Only public data: private, deleted or region-blocked videos answer with HTTP 404 instead of a half-filled object.

Endpoints used in this guide

GET/ytb/youtube-search-videos

Search Videos · YouTube API

GET/ytb/youtube-channel-videos

Channel Videos · YouTube API

GET/ytb/youtube-video-details

Video Details · YouTube API

All parameters in the API reference

Try it with your own data

The free plan includes 100 requests a month, usable on every platform – enough to follow this guide end to end.