How to scrape YouTube
YouTube (youtube.com) is a social platform. This guide is built from our own checks of its public pages: what the pages contain, whether our requests get through right now, and the request settings that worked.
Ujeebu scrapes any public website. Not listed here? Try any URL in the Playground or ask us about a site.
18 of 21 of our checks passed in the last 7 days (85.7%).
Last check 2026-11-22 20:02 UTC · last pass 2026-11-22 13:33 UTC · checked with our own requests, never customer data.
Recipe one call
Use the YouTube recipe: send the URL, get JSON
- Search and listing pages
recipe=youtube/listing - Detail pages
recipe=youtube/detail - Search: query, sort
curl -G 'https://api.ujeebu.com/scrape' \
-H "ApiKey: $UJEEBU_API_KEY" \
--data-urlencode 'url=https://www.youtube.com/results?search_query=cooking+pasta' \
--data-urlencode 'recipe=youtube/listing'
The answer is {"result": {...}} with the fields of the recipe. Billed like any /scrape call: successful responses cost credits; blocked, timed-out and failed requests are free.
Run the code on this page with your own key: 5,000 free credits for 7 days, no card. Get a free API key →
Recipes
Call a recipe by name with the recipe parameter: the Scrape API applies its extract rules and the settings that work on YouTube. Each recipe was run on two real YouTube pages and keeps only the fields that came back on both; it is checked again every week, and hidden if it stops working.
Search and listing pages
Validated 2026-11-19One call: recipe=youtube/listing 5 credits (JS) a page
curl -G 'https://api.ujeebu.com/scrape' \
-H "ApiKey: $UJEEBU_API_KEY" \
--data-urlencode 'url=https://www.youtube.com/results?search_query=cooking+pasta' \
--data-urlencode 'recipe=youtube/listing'
The answer is {"result": {...}} with the fields below; the Ujb-Recipe header names the version (for example youtube/listing@v1) and Ujb-Credits the cost.
Search with parameters: query, sort
No URL needed: send recipe=youtube/search with the parameters below. The API builds the search URL (returned in the Ujb-Url header and the url field), applies the youtube/listing recipe and answers the same JSON, at the same credits.
| Parameter | Type | What it is |
|---|---|---|
query * | text | Search words. |
sort | relevance | newest | views | rating | Sort order: relevance (the default), newest, views or rating. Default: relevance. |
One call, for {"query":"cooking pasta"}:
curl -G 'https://api.ujeebu.com/scrape' \
-H 'ApiKey: YOUR_API_KEY' \
-d 'recipe=youtube/search' \
--data-urlencode 'query=cooking pasta'
A missing or invalid parameter answers 400 with param naming it (not billed). Try it in the Playground or the Request builder (Search mode). Have the URL already? url=https://www.youtube.com/results?search_query=cooking%20pasta with recipe=youtube/listing works too. Search in the docs
What this recipe extracts
| Field | Type | Example |
|---|---|---|
videos | list of 3+ items | |
videos[].duration | text | 1:32 |
videos[].image | image URL | https://i.ytimg.com/vi/UYhKDweME3A/hq720.jpg |
videos[].published | text | 12y ago |
videos[].title | text | How To Cook The Perfect Pasta | Gordon Ramsay |
videos[].url | URL | https://www.youtube.com/watch?v=UYhKDweME3A |
videos[].views | text | 12,071,276 views |
Examples from www.youtube.com/results on 2026-11-19, shortened.
Sample output (real, trimmed)
{
"videos": [
{
"duration": "1:32",
"image": "https://i.ytimg.com/vi/UYhKDweME3A/hq720.jpg",
"published": "12y ago",
"title": "How To Cook The Perfect Pasta | Gordon Ramsay",
"url": "https://www.youtube.com/watch?v=UYhKDweME3A",
"views": "12,110,378 views"
},
{
"duration": "4:15",
"image": "https://i.ytimg.com/vi/VnwNR5qR9ow/hq720.jpg",
"published": "8y ago",
"title": "How to Boil Pasta",
"url": "https://www.youtube.com/watch?v=VnwNR5qR9ow",
"views": "355,486 views"
},
{
"duration": "0:16",
"image": "https://i.ytimg.com/vi/NlsTuBwmNvU/hq720.jpg",
"published": "2y ago",
"title": "How to make $75 PASTA",
"url": "https://www.youtube.com/watch?v=NlsTuBwmNvU",
"views": "96,204,520 views"
}
]
}
extract_rules (1 rule): the rules behind the recipe
The API applies these rules and the settings js=true for you when you send recipe=youtube/listing. To change what comes back, send your own extract_rules (they replace the recipe's) or any setting (yours always win). Sites without a recipe work the same way with extract rules.
{
"videos": {
"type": "fn",
"fn": "const d = window.ytInitialData; if (!d) return null; const out = []; const t = x => x ? (x.simpleText || (x.runs || []).map(r => r.text).join('')) || null : null; const walk = o => { if (!o || typeof o !== 'object' || out.length >= 60) return; if (o.videoRenderer && o.videoRenderer.videoId) { const v = o.videoRenderer; const th = (v.thumbnail && v.thumbnail.thumbnails) || []; out.push({ title: t(v.title), url: 'https://www.youtube.com/watch?v=' + v.videoId, views: t(v.viewCountText), published: t(v.publishedTimeText), duration: t(v.lengthText), image: th.length ? th[th.length - 1].url.split('?')[0] : null }); return; } for (const k in o) walk(o[k]); }; walk(d.contents); return out;"
}
}
Detail pages
Validated 2026-11-18One call: recipe=youtube/detail 5 credits (JS) a page
curl -G 'https://api.ujeebu.com/scrape' \
-H "ApiKey: $UJEEBU_API_KEY" \
--data-urlencode 'url=https://www.youtube.com/watch?v=dQw4w9WgXcQ' \
--data-urlencode 'recipe=youtube/detail'
The answer is {"result": {...}} with the fields below; the Ujb-Recipe header names the version (for example youtube/detail@v1) and Ujb-Credits the cost.
What this recipe extracts
| Field | Type | Example |
|---|---|---|
video.name | text | Rick Astley - Never Gonna Give You Up (Official Video) (4K Remaster) |
video.thumbnail | image URL | https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg |
video.uploaded | date | 2009-10-24T23:57:33-07:00 |
description | text | The official video for “Never Gonna Give You Up” by Rick Astley. Ne... |
image | image URL | https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg |
url | URL | https://www.youtube.com/watch?v=dQw4w9WgXcQ |
Examples from www.youtube.com/watch on 2026-11-18, shortened.
Sample output (real, trimmed)
{
"video": {
"name": "Rick Astley - Never Gonna Give You Up (Official Video) (4K Remaster)",
"thumbnail": "https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg",
"uploaded": "2009-10-24T23:57:33-07:00"
},
"description": "The official video for “Never Gonna Give You Up” by Rick Astley. Never: The Autobiography 📚 OUT NOW! Follow this link to get your copy and listen to Rick’s ...",
"image": "https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg",
"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
}
extract_rules (4 rules): the rules behind the recipe
The API applies these rules and the settings js=true for you when you send recipe=youtube/detail. To change what comes back, send your own extract_rules (they replace the recipe's) or any setting (yours always win). Sites without a recipe work the same way with extract rules.
{
"video": {
"type": "fn",
"fn": "const T = ['VideoObject']; const n = [...document.querySelectorAll('script[type=\"application/ld+json\"]')].flatMap(s => { try { return [].concat(JSON.parse(s.textContent)).flatMap(x => x['@graph'] || [x]); } catch (e) { return []; } }).find(x => x && [].concat(x['@type']).some(t => T.includes(t))); if (!n) return null; const g = p => p.split('|').map(q => q.split('.').reduce((v, k) => v == null ? v : (Array.isArray(v) ? v[0] : v)?.[k], n)).find(v => v != null && v !== ''); const all = v => Array.isArray(v) ? v.map(all).filter(x => x != null).join(', ') : (v && typeof v === 'object' ? (v.name ?? v['@id'] ?? null) : (typeof v === 'string' ? v.replace('https://schema.org/', '').replace('http://schema.org/', '') : v ?? null)); const one = v => all(Array.isArray(v) ? v[0] : v); return { name: all(g('name')), thumbnail: one(g('thumbnailUrl')), uploaded: all(g('uploadDate')) };"
},
"description": {
"selector": "meta[property=\"og:description\"]",
"type": "attr",
"attribute": "content"
},
"image": {
"selector": "meta[property=\"og:image\"]",
"type": "attr",
"attribute": "content"
},
"url": {
"selector": "link[rel=\"canonical\"]",
"type": "attr",
"attribute": "href"
}
}
Code
Complete scripts: set the UJEEBU_API_KEY environment variable and run them as they are. Each one calls the recipe by name (the Go SDK has no recipe field, so the Go script sends the recipe's rules and settings itself), prints the extracted JSON, and prints the credits the request cost (the Ujb-Credits response header) on stderr. A non-200 answer stops the script with the API's error message.
Search and listing pages
Runs the recipe on the two pages it was validated on, one after the other.
pip install ujeebu-python==0.1.5 # Scrape YouTube search and listing pages with the Ujeebu Scrape API.
# Calls the recipe youtube/listing: the API applies its extract rules and validated settings (validated 2026-11-19). Send extract_rules or any setting to override them.
# Uses the official SDK ujeebu-python 0.1.5: pip install ujeebu-python==0.1.5
# Run: UJEEBU_API_KEY=your_key python3 youtube_listing_sdk.py
import json
import os
import sys
import time
import requests
from ujeebu_python import UjeebuClient
API_KEY = os.environ.get("UJEEBU_API_KEY")
URLS = [
"https://www.youtube.com/results?search_query=cooking+pasta",
"https://www.youtube.com/results?search_query=nba+highlights",
]
RECIPE = "youtube/listing" # rules and settings come from the recipe; add your own to override them
def scrape(client, url):
# a GET with recipe=: the API applies the recipe and answers {"result": {...}}
try:
response = client.scrape(url, params={"recipe": RECIPE})
except requests.RequestException as error:
sys.exit(f"Request failed for {url}: {error}")
if response.status_code != 200:
try:
message = response.json().get("message", response.text)
except ValueError:
message = response.text
sys.exit(f"HTTP {response.status_code} for {url}: {str(message)[:300]}")
print(f"Ujb-Credits: {response.headers.get('Ujb-Credits')}, Ujb-Recipe: {response.headers.get('Ujb-Recipe')}", file=sys.stderr)
return response.json()["result"]
if not API_KEY:
sys.exit("Set the UJEEBU_API_KEY environment variable.")
client = UjeebuClient(api_key=API_KEY)
for i, url in enumerate(URLS):
if i:
time.sleep(2) # be polite: one page at a time
result = scrape(client, url)
for item in result.get("videos") or []:
print(item.get("title"), item.get("views"), item.get("duration"))
# Example output:
# How To Cook The Perfect Pasta | Gordo... 12,110,378 views 1:32
# How to Boil Pasta 355,486 views 4:15
# every field: print(json.dumps(result, indent=2, ensure_ascii=False))
npm install @ujeebu-org/ujeebu-sdk@0.1.2 // Scrape YouTube search and listing pages with the Ujeebu Scrape API.
// Calls the recipe youtube/listing: the API applies its extract rules and validated settings (validated 2026-11-19). Send extract_rules or any setting to override them.
// Uses the official SDK @ujeebu-org/ujeebu-sdk 0.1.2: npm install @ujeebu-org/ujeebu-sdk@0.1.2
// Run: UJEEBU_API_KEY=your_key node youtube_listing_sdk.mjs
import { UjeebuClient } from '@ujeebu-org/ujeebu-sdk';
const API_KEY = process.env.UJEEBU_API_KEY;
const URLS = [
"https://www.youtube.com/results?search_query=cooking+pasta",
"https://www.youtube.com/results?search_query=nba+highlights",
];
const RECIPE = "youtube/listing"; // rules and settings come from the recipe; add your own to override them
async function scrape(client, url) {
let res;
try {
// a GET with recipe=: the API applies the recipe and answers { result: {...} }
res = await client.scrape(url, { recipe: RECIPE });
} catch (err) {
const status = err.response?.status ?? 'error';
const message = err.response?.data?.message ?? err.message;
console.error(`HTTP ${status} for ${url}: ${String(message).slice(0, 300)}`);
process.exit(1);
}
console.error(`Ujb-Credits: ${res.headers['ujb-credits']}, Ujb-Recipe: ${res.headers['ujb-recipe']}`);
return res.data.result;
}
if (!API_KEY) {
console.error('Set the UJEEBU_API_KEY environment variable.');
process.exit(1);
}
const client = new UjeebuClient(API_KEY);
const pause = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
for (const [i, url] of URLS.entries()) {
if (i) await pause(2000); // be polite: one page at a time
const result = await scrape(client, url);
for (const item of (result?.videos ?? [])) {
console.log(item.title, item.views, item.duration);
}
// Example output:
// How To Cook The Perfect Pasta | Gordo... 12,110,378 views 1:32
// How to Boil Pasta 355,486 views 4:15
// every field: console.log(JSON.stringify(result, null, 2));
}
pip install requests # Scrape YouTube search and listing pages with the Ujeebu Scrape API.
# Calls the recipe youtube/listing: the API applies its extract rules and validated settings (validated 2026-11-19). Send extract_rules or any setting to override them.
# Run: UJEEBU_API_KEY=your_key python3 youtube_listing.py (pip install requests)
import json
import os
import sys
import time
import requests
API_URL = "https://api.ujeebu.com/scrape"
API_KEY = os.environ.get("UJEEBU_API_KEY")
URLS = [
"https://www.youtube.com/results?search_query=cooking+pasta",
"https://www.youtube.com/results?search_query=nba+highlights",
]
RECIPE = "youtube/listing" # rules and settings come from the recipe; add your own to override them
def scrape(url):
response = requests.get(
API_URL,
headers={"ApiKey": API_KEY},
params={"url": url, "recipe": RECIPE},
timeout=180,
)
if response.status_code != 200:
try:
message = response.json().get("message", response.text)
except ValueError:
message = response.text
sys.exit(f"HTTP {response.status_code} for {url}: {str(message)[:300]}")
print(f"Ujb-Credits: {response.headers.get('Ujb-Credits')}, Ujb-Recipe: {response.headers.get('Ujb-Recipe')}", file=sys.stderr)
return response.json()["result"]
if not API_KEY:
sys.exit("Set the UJEEBU_API_KEY environment variable.")
for i, url in enumerate(URLS):
if i:
time.sleep(2) # be polite: one page at a time
result = scrape(url)
for item in result.get("videos") or []:
print(item.get("title"), item.get("views"), item.get("duration"))
# Example output:
# How To Cook The Perfect Pasta | Gordo... 12,110,378 views 1:32
# How to Boil Pasta 355,486 views 4:15
# every field: print(json.dumps(result, indent=2, ensure_ascii=False))
// Scrape YouTube search and listing pages with the Ujeebu Scrape API.
// Calls the recipe youtube/listing: the API applies its extract rules and validated settings (validated 2026-11-19). Send extract_rules or any setting to override them.
// Run: UJEEBU_API_KEY=your_key node youtube_listing.mjs (Node.js 18 or later)
const API_URL = 'https://api.ujeebu.com/scrape';
const API_KEY = process.env.UJEEBU_API_KEY;
const URLS = [
"https://www.youtube.com/results?search_query=cooking+pasta",
"https://www.youtube.com/results?search_query=nba+highlights",
];
const RECIPE = "youtube/listing"; // rules and settings come from the recipe; add your own to override them
async function scrape(url) {
const params = new URLSearchParams({ url, recipe: RECIPE });
const res = await fetch(`${API_URL}?${params}`, {
headers: { ApiKey: API_KEY },
signal: AbortSignal.timeout(180000),
});
const text = await res.text();
if (res.status !== 200) {
let message = text;
try {
message = JSON.parse(text).message ?? text;
} catch {}
console.error(`HTTP ${res.status} for ${url}: ${String(message).slice(0, 300)}`);
process.exit(1);
}
console.error(`Ujb-Credits: ${res.headers.get('ujb-credits')}, Ujb-Recipe: ${res.headers.get('ujb-recipe')}`);
return JSON.parse(text).result;
}
if (!API_KEY) {
console.error('Set the UJEEBU_API_KEY environment variable.');
process.exit(1);
}
const pause = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
for (const [i, url] of URLS.entries()) {
if (i) await pause(2000); // be polite: one page at a time
const result = await scrape(url);
for (const item of (result?.videos ?? [])) {
console.log(item.title, item.views, item.duration);
}
// Example output:
// How To Cook The Perfect Pasta | Gordo... 12,110,378 views 1:32
// How to Boil Pasta 355,486 views 4:15
// every field: console.log(JSON.stringify(result, null, 2));
}
#!/usr/bin/env bash
# Scrape YouTube search and listing pages with the Ujeebu Scrape API.
# Calls the recipe youtube/listing: the API applies its extract rules and validated settings (validated 2026-11-19). Send extract_rules or any setting to override them.
# Run: UJEEBU_API_KEY=your_key bash youtube_listing.sh (curl 7.76 or later)
set -euo pipefail
curl -sS --fail-with-body --max-time 180 -D headers.txt -G 'https://api.ujeebu.com/scrape' \
-H "ApiKey: ${UJEEBU_API_KEY:?Set the UJEEBU_API_KEY environment variable.}" \
--data-urlencode 'url=https://www.youtube.com/results?search_query=cooking+pasta' \
--data-urlencode 'recipe=youtube/listing'
echo
grep -i -E '^ujb-(credits|recipe)' headers.txt >&2
<?php
// Scrape YouTube search and listing pages with the Ujeebu Scrape API.
// Calls the recipe youtube/listing: the API applies its extract rules and validated settings (validated 2026-11-19). Send extract_rules or any setting to override them.
// Run: UJEEBU_API_KEY=your_key php youtube_listing.php (PHP 7.4 or later with curl)
$apiKey = getenv('UJEEBU_API_KEY') ?: exit("Set the UJEEBU_API_KEY environment variable.\n");
$urls = [
'https://www.youtube.com/results?search_query=cooking+pasta',
'https://www.youtube.com/results?search_query=nba+highlights',
];
$recipe = 'youtube/listing'; // rules and settings come from the recipe; add your own to override them
function scrape(string $url, string $apiKey, string $recipe)
{
$ch = curl_init('https://api.ujeebu.com/scrape?' . http_build_query(['url' => $url, 'recipe' => $recipe]));
$headers = [];
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 180,
CURLOPT_HTTPHEADER => ['ApiKey: ' . $apiKey],
CURLOPT_HEADERFUNCTION => function ($ch, $line) use (&$headers) {
if (strpos($line, ':') !== false) {
[$k, $v] = explode(':', $line, 2);
$headers[strtolower(trim($k))] = trim($v);
}
return strlen($line);
},
]);
$body = curl_exec($ch);
if ($body === false) {
fwrite(STDERR, 'Request failed: ' . curl_error($ch) . "\n");
exit(1);
}
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
if ($status !== 200) {
$message = json_decode($body, true)['message'] ?? $body;
fwrite(STDERR, "HTTP $status for $url: " . substr((string) $message, 0, 300) . "\n");
exit(1);
}
fwrite(STDERR, 'Ujb-Credits: ' . ($headers['ujb-credits'] ?? '?') . ', Ujb-Recipe: ' . ($headers['ujb-recipe'] ?? '?') . "\n");
return json_decode($body, true)['result'];
}
foreach ($urls as $i => $url) {
if ($i > 0) {
sleep(2); // be polite: one page at a time
}
$result = scrape($url, $apiKey, $recipe);
foreach ($result['videos'] ?? [] as $item) {
echo implode(' ', [$item['title'] ?? '', $item['views'] ?? '', $item['duration'] ?? '']), "\n";
}
// Example output:
// How To Cook The Perfect Pasta | Gordo... 12,110,378 views 1:32
// How to Boil Pasta 355,486 views 4:15
// every field: echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), "\n";
}
go mod init scraper && go get github.com/ujeebu/ujeebu-go@v0.1.8 // Scrape YouTube search and listing pages with the Ujeebu Scrape API.
// Sends the extract rules and settings of the recipe youtube/listing itself: the Go SDK v0.1.8 has no recipe field and always sends js, which would override the recipe.
// Uses the official SDK github.com/ujeebu/ujeebu-go v0.1.8: go mod init scraper && go get github.com/ujeebu/ujeebu-go@v0.1.8
// Run: UJEEBU_API_KEY=your_key go run youtube_listing.go
package main
import (
"encoding/json"
"errors"
"fmt"
"os"
"time"
ujeebu "github.com/ujeebu/ujeebu-go"
)
var urls = []string{
"https://www.youtube.com/results?search_query=cooking+pasta",
"https://www.youtube.com/results?search_query=nba+highlights",
}
// The extract rules of the recipe, as the JSON the API takes.
const extractRulesJSON = `{
"videos": {
"type": "fn",
"fn": "const d = window.ytInitialData; if (!d) return null; const out = []; const t = x => x ? (x.simpleText || (x.runs || []).map(r => r.text).join('')) || null : null; const walk = o => { if (!o || typeof o !== 'object' || out.length >= 60) return; if (o.videoRenderer && o.videoRenderer.videoId) { const v = o.videoRenderer; const th = (v.thumbnail && v.thumbnail.thumbnails) || []; out.push({ title: t(v.title), url: 'https://www.youtube.com/watch?v=' + v.videoId, views: t(v.viewCountText), published: t(v.publishedTimeText), duration: t(v.lengthText), image: th.length ? th[th.length - 1].url.split('?')[0] : null }); return; } for (const k in o) walk(o[k]); }; walk(d.contents); return out;"
}
}`
var extractRules map[string]any
func fail(format string, args ...any) {
fmt.Fprintf(os.Stderr, format+"\n", args...)
os.Exit(1)
}
func short(s string) string {
if len(s) > 300 {
return s[:300]
}
return s
}
func params(target string) ujeebu.ScrapeParams {
p := ujeebu.ScrapeParams{URL: target}
p.JS = true
p.ExtractRules = extractRules
return p
}
func scrape(client *ujeebu.Client, target string) map[string]any {
// the int is the credits the request cost (the Ujb-Credits header), not an HTTP status
resp, credits, err := client.Scrape(params(target))
if err != nil {
var apiErr *ujeebu.APIError
if errors.As(err, &apiErr) {
fail("HTTP %d for %s: %s", apiErr.StatusCode, target, short(apiErr.Message))
}
fail("Request failed for %s: %v", target, err)
}
fmt.Fprintf(os.Stderr, "Ujb-Credits: %d\n", credits)
result, _ := resp.Result.(map[string]any)
return result
}
func printJSON(v any) {
enc := json.NewEncoder(os.Stdout)
enc.SetEscapeHTML(false)
enc.SetIndent("", " ")
if err := enc.Encode(v); err != nil {
fail("Cannot print the result: %v", err)
}
}
func main() {
apiKey := os.Getenv("UJEEBU_API_KEY")
if apiKey == "" {
fail("Set the UJEEBU_API_KEY environment variable.")
}
if err := json.Unmarshal([]byte(extractRulesJSON), &extractRules); err != nil {
fail("Bad extract rules: %v", err)
}
client, err := ujeebu.NewClient(apiKey, ujeebu.WithTimeout(180*time.Second))
if err != nil {
fail("%v", err)
}
for i, target := range urls {
if i > 0 {
time.Sleep(2 * time.Second) // be polite: one page at a time
}
printJSON(scrape(client, target))
}
}
Detail pages
Runs the recipe on the two pages it was validated on, one after the other.
pip install ujeebu-python==0.1.5 # Scrape YouTube detail pages with the Ujeebu Scrape API.
# Calls the recipe youtube/detail: the API applies its extract rules and validated settings (validated 2026-11-18). Send extract_rules or any setting to override them.
# Uses the official SDK ujeebu-python 0.1.5: pip install ujeebu-python==0.1.5
# Run: UJEEBU_API_KEY=your_key python3 youtube_detail_sdk.py
import json
import os
import sys
import time
import requests
from ujeebu_python import UjeebuClient
API_KEY = os.environ.get("UJEEBU_API_KEY")
URLS = [
"https://www.youtube.com/watch?v=dQw4w9WgXcQ",
"https://www.youtube.com/watch?v=kJQP7kiw5Fk",
]
RECIPE = "youtube/detail" # rules and settings come from the recipe; add your own to override them
def scrape(client, url):
# a GET with recipe=: the API applies the recipe and answers {"result": {...}}
try:
response = client.scrape(url, params={"recipe": RECIPE})
except requests.RequestException as error:
sys.exit(f"Request failed for {url}: {error}")
if response.status_code != 200:
try:
message = response.json().get("message", response.text)
except ValueError:
message = response.text
sys.exit(f"HTTP {response.status_code} for {url}: {str(message)[:300]}")
print(f"Ujb-Credits: {response.headers.get('Ujb-Credits')}, Ujb-Recipe: {response.headers.get('Ujb-Recipe')}", file=sys.stderr)
return response.json()["result"]
if not API_KEY:
sys.exit("Set the UJEEBU_API_KEY environment variable.")
client = UjeebuClient(api_key=API_KEY)
for i, url in enumerate(URLS):
if i:
time.sleep(2) # be polite: one page at a time
result = scrape(client, url)
video = result.get("video") or {}
print(video.get("name"), video.get("uploaded"))
# Example output: Rick Astley - Never Gonna Give You Up... 2009-10-24T23:57:33-07:00
# every field: print(json.dumps(result, indent=2, ensure_ascii=False))
npm install @ujeebu-org/ujeebu-sdk@0.1.2 // Scrape YouTube detail pages with the Ujeebu Scrape API.
// Calls the recipe youtube/detail: the API applies its extract rules and validated settings (validated 2026-11-18). Send extract_rules or any setting to override them.
// Uses the official SDK @ujeebu-org/ujeebu-sdk 0.1.2: npm install @ujeebu-org/ujeebu-sdk@0.1.2
// Run: UJEEBU_API_KEY=your_key node youtube_detail_sdk.mjs
import { UjeebuClient } from '@ujeebu-org/ujeebu-sdk';
const API_KEY = process.env.UJEEBU_API_KEY;
const URLS = [
"https://www.youtube.com/watch?v=dQw4w9WgXcQ",
"https://www.youtube.com/watch?v=kJQP7kiw5Fk",
];
const RECIPE = "youtube/detail"; // rules and settings come from the recipe; add your own to override them
async function scrape(client, url) {
let res;
try {
// a GET with recipe=: the API applies the recipe and answers { result: {...} }
res = await client.scrape(url, { recipe: RECIPE });
} catch (err) {
const status = err.response?.status ?? 'error';
const message = err.response?.data?.message ?? err.message;
console.error(`HTTP ${status} for ${url}: ${String(message).slice(0, 300)}`);
process.exit(1);
}
console.error(`Ujb-Credits: ${res.headers['ujb-credits']}, Ujb-Recipe: ${res.headers['ujb-recipe']}`);
return res.data.result;
}
if (!API_KEY) {
console.error('Set the UJEEBU_API_KEY environment variable.');
process.exit(1);
}
const client = new UjeebuClient(API_KEY);
const pause = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
for (const [i, url] of URLS.entries()) {
if (i) await pause(2000); // be polite: one page at a time
const result = await scrape(client, url);
const video = result?.video ?? {};
console.log(video.name, video.uploaded);
// Example output: Rick Astley - Never Gonna Give You Up... 2009-10-24T23:57:33-07:00
// every field: console.log(JSON.stringify(result, null, 2));
}
pip install requests # Scrape YouTube detail pages with the Ujeebu Scrape API.
# Calls the recipe youtube/detail: the API applies its extract rules and validated settings (validated 2026-11-18). Send extract_rules or any setting to override them.
# Run: UJEEBU_API_KEY=your_key python3 youtube_detail.py (pip install requests)
import json
import os
import sys
import time
import requests
API_URL = "https://api.ujeebu.com/scrape"
API_KEY = os.environ.get("UJEEBU_API_KEY")
URLS = [
"https://www.youtube.com/watch?v=dQw4w9WgXcQ",
"https://www.youtube.com/watch?v=kJQP7kiw5Fk",
]
RECIPE = "youtube/detail" # rules and settings come from the recipe; add your own to override them
def scrape(url):
response = requests.get(
API_URL,
headers={"ApiKey": API_KEY},
params={"url": url, "recipe": RECIPE},
timeout=180,
)
if response.status_code != 200:
try:
message = response.json().get("message", response.text)
except ValueError:
message = response.text
sys.exit(f"HTTP {response.status_code} for {url}: {str(message)[:300]}")
print(f"Ujb-Credits: {response.headers.get('Ujb-Credits')}, Ujb-Recipe: {response.headers.get('Ujb-Recipe')}", file=sys.stderr)
return response.json()["result"]
if not API_KEY:
sys.exit("Set the UJEEBU_API_KEY environment variable.")
for i, url in enumerate(URLS):
if i:
time.sleep(2) # be polite: one page at a time
result = scrape(url)
video = result.get("video") or {}
print(video.get("name"), video.get("uploaded"))
# Example output: Rick Astley - Never Gonna Give You Up... 2009-10-24T23:57:33-07:00
# every field: print(json.dumps(result, indent=2, ensure_ascii=False))
// Scrape YouTube detail pages with the Ujeebu Scrape API.
// Calls the recipe youtube/detail: the API applies its extract rules and validated settings (validated 2026-11-18). Send extract_rules or any setting to override them.
// Run: UJEEBU_API_KEY=your_key node youtube_detail.mjs (Node.js 18 or later)
const API_URL = 'https://api.ujeebu.com/scrape';
const API_KEY = process.env.UJEEBU_API_KEY;
const URLS = [
"https://www.youtube.com/watch?v=dQw4w9WgXcQ",
"https://www.youtube.com/watch?v=kJQP7kiw5Fk",
];
const RECIPE = "youtube/detail"; // rules and settings come from the recipe; add your own to override them
async function scrape(url) {
const params = new URLSearchParams({ url, recipe: RECIPE });
const res = await fetch(`${API_URL}?${params}`, {
headers: { ApiKey: API_KEY },
signal: AbortSignal.timeout(180000),
});
const text = await res.text();
if (res.status !== 200) {
let message = text;
try {
message = JSON.parse(text).message ?? text;
} catch {}
console.error(`HTTP ${res.status} for ${url}: ${String(message).slice(0, 300)}`);
process.exit(1);
}
console.error(`Ujb-Credits: ${res.headers.get('ujb-credits')}, Ujb-Recipe: ${res.headers.get('ujb-recipe')}`);
return JSON.parse(text).result;
}
if (!API_KEY) {
console.error('Set the UJEEBU_API_KEY environment variable.');
process.exit(1);
}
const pause = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
for (const [i, url] of URLS.entries()) {
if (i) await pause(2000); // be polite: one page at a time
const result = await scrape(url);
const video = result?.video ?? {};
console.log(video.name, video.uploaded);
// Example output: Rick Astley - Never Gonna Give You Up... 2009-10-24T23:57:33-07:00
// every field: console.log(JSON.stringify(result, null, 2));
}
#!/usr/bin/env bash
# Scrape YouTube detail pages with the Ujeebu Scrape API.
# Calls the recipe youtube/detail: the API applies its extract rules and validated settings (validated 2026-11-18). Send extract_rules or any setting to override them.
# Run: UJEEBU_API_KEY=your_key bash youtube_detail.sh (curl 7.76 or later)
set -euo pipefail
curl -sS --fail-with-body --max-time 180 -D headers.txt -G 'https://api.ujeebu.com/scrape' \
-H "ApiKey: ${UJEEBU_API_KEY:?Set the UJEEBU_API_KEY environment variable.}" \
--data-urlencode 'url=https://www.youtube.com/watch?v=dQw4w9WgXcQ' \
--data-urlencode 'recipe=youtube/detail'
echo
grep -i -E '^ujb-(credits|recipe)' headers.txt >&2
<?php
// Scrape YouTube detail pages with the Ujeebu Scrape API.
// Calls the recipe youtube/detail: the API applies its extract rules and validated settings (validated 2026-11-18). Send extract_rules or any setting to override them.
// Run: UJEEBU_API_KEY=your_key php youtube_detail.php (PHP 7.4 or later with curl)
$apiKey = getenv('UJEEBU_API_KEY') ?: exit("Set the UJEEBU_API_KEY environment variable.\n");
$urls = [
'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
'https://www.youtube.com/watch?v=kJQP7kiw5Fk',
];
$recipe = 'youtube/detail'; // rules and settings come from the recipe; add your own to override them
function scrape(string $url, string $apiKey, string $recipe)
{
$ch = curl_init('https://api.ujeebu.com/scrape?' . http_build_query(['url' => $url, 'recipe' => $recipe]));
$headers = [];
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 180,
CURLOPT_HTTPHEADER => ['ApiKey: ' . $apiKey],
CURLOPT_HEADERFUNCTION => function ($ch, $line) use (&$headers) {
if (strpos($line, ':') !== false) {
[$k, $v] = explode(':', $line, 2);
$headers[strtolower(trim($k))] = trim($v);
}
return strlen($line);
},
]);
$body = curl_exec($ch);
if ($body === false) {
fwrite(STDERR, 'Request failed: ' . curl_error($ch) . "\n");
exit(1);
}
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
if ($status !== 200) {
$message = json_decode($body, true)['message'] ?? $body;
fwrite(STDERR, "HTTP $status for $url: " . substr((string) $message, 0, 300) . "\n");
exit(1);
}
fwrite(STDERR, 'Ujb-Credits: ' . ($headers['ujb-credits'] ?? '?') . ', Ujb-Recipe: ' . ($headers['ujb-recipe'] ?? '?') . "\n");
return json_decode($body, true)['result'];
}
foreach ($urls as $i => $url) {
if ($i > 0) {
sleep(2); // be polite: one page at a time
}
$result = scrape($url, $apiKey, $recipe);
$video = $result['video'] ?? [];
echo implode(' ', [$video['name'] ?? '', $video['uploaded'] ?? '']), "\n";
// Example output: Rick Astley - Never Gonna Give You Up... 2009-10-24T23:57:33-07:00
// every field: echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), "\n";
}
go mod init scraper && go get github.com/ujeebu/ujeebu-go@v0.1.8 // Scrape YouTube detail pages with the Ujeebu Scrape API.
// Sends the extract rules and settings of the recipe youtube/detail itself: the Go SDK v0.1.8 has no recipe field and always sends js, which would override the recipe.
// Uses the official SDK github.com/ujeebu/ujeebu-go v0.1.8: go mod init scraper && go get github.com/ujeebu/ujeebu-go@v0.1.8
// Run: UJEEBU_API_KEY=your_key go run youtube_detail.go
package main
import (
"encoding/json"
"errors"
"fmt"
"os"
"time"
ujeebu "github.com/ujeebu/ujeebu-go"
)
var urls = []string{
"https://www.youtube.com/watch?v=dQw4w9WgXcQ",
"https://www.youtube.com/watch?v=kJQP7kiw5Fk",
}
// The extract rules of the recipe, as the JSON the API takes.
const extractRulesJSON = `{
"video": {
"type": "fn",
"fn": "const T = ['VideoObject']; const n = [...document.querySelectorAll('script[type=\"application/ld+json\"]')].flatMap(s => { try { return [].concat(JSON.parse(s.textContent)).flatMap(x => x['@graph'] || [x]); } catch (e) { return []; } }).find(x => x && [].concat(x['@type']).some(t => T.includes(t))); if (!n) return null; const g = p => p.split('|').map(q => q.split('.').reduce((v, k) => v == null ? v : (Array.isArray(v) ? v[0] : v)?.[k], n)).find(v => v != null && v !== ''); const all = v => Array.isArray(v) ? v.map(all).filter(x => x != null).join(', ') : (v && typeof v === 'object' ? (v.name ?? v['@id'] ?? null) : (typeof v === 'string' ? v.replace('https://schema.org/', '').replace('http://schema.org/', '') : v ?? null)); const one = v => all(Array.isArray(v) ? v[0] : v); return { name: all(g('name')), thumbnail: one(g('thumbnailUrl')), uploaded: all(g('uploadDate')) };"
},
"description": {
"selector": "meta[property=\"og:description\"]",
"type": "attr",
"attribute": "content"
},
"image": {
"selector": "meta[property=\"og:image\"]",
"type": "attr",
"attribute": "content"
},
"url": {
"selector": "link[rel=\"canonical\"]",
"type": "attr",
"attribute": "href"
}
}`
var extractRules map[string]any
func fail(format string, args ...any) {
fmt.Fprintf(os.Stderr, format+"\n", args...)
os.Exit(1)
}
func short(s string) string {
if len(s) > 300 {
return s[:300]
}
return s
}
func params(target string) ujeebu.ScrapeParams {
p := ujeebu.ScrapeParams{URL: target}
p.JS = true
p.ExtractRules = extractRules
return p
}
func scrape(client *ujeebu.Client, target string) map[string]any {
// the int is the credits the request cost (the Ujb-Credits header), not an HTTP status
resp, credits, err := client.Scrape(params(target))
if err != nil {
var apiErr *ujeebu.APIError
if errors.As(err, &apiErr) {
fail("HTTP %d for %s: %s", apiErr.StatusCode, target, short(apiErr.Message))
}
fail("Request failed for %s: %v", target, err)
}
fmt.Fprintf(os.Stderr, "Ujb-Credits: %d\n", credits)
result, _ := resp.Result.(map[string]any)
return result
}
func printJSON(v any) {
enc := json.NewEncoder(os.Stdout)
enc.SetEscapeHTML(false)
enc.SetIndent("", " ")
if err := enc.Encode(v); err != nil {
fail("Cannot print the result: %v", err)
}
}
func main() {
apiKey := os.Getenv("UJEEBU_API_KEY")
if apiKey == "" {
fail("Set the UJEEBU_API_KEY environment variable.")
}
if err := json.Unmarshal([]byte(extractRulesJSON), &extractRules); err != nil {
fail("Bad extract rules: %v", err)
}
client, err := ujeebu.NewClient(apiKey, ujeebu.WithTimeout(180*time.Second))
if err != nil {
fail("%v", err)
}
for i, target := range urls {
if i > 0 {
time.Sleep(2 * time.Second) // be polite: one page at a time
}
printJSON(scrape(client, target))
}
}
SDK tabs use the official Ujeebu SDKs (ujeebu-python 0.1.5, @ujeebu-org/ujeebu-sdk 0.1.2, github.com/ujeebu/ujeebu-go v0.1.8); there is no PHP SDK, so the PHP tab calls the API with curl. For agents and scripts, the same status and settings are at /scrape/youtube.json.
Try it yourself
Run this on YouTube with your own key
Get a free API key, set UJEEBU_API_KEY and run any script above as it is. 5,000 free credits for 7 days, no card.
URL patterns and pagination
What the URLs look like, read from the pages our checks fetched.
Search and listing pages
- Pattern
https://www.youtube.com/results?search_query={search_query}- Next pages
- We did not see a next-page link on the pages we fetched. Results may load as you scroll: try
scroll_down. - Validated on
https://www.youtube.com/results?search_query=cooking+pastahttps://www.youtube.com/results?search_query=nba+highlights
Detail pages
- Validated on
https://www.youtube.com/watch?v=dQw4w9WgXcQhttps://www.youtube.com/watch?v=kJQP7kiw5Fk
Settings that work today
From our health checks over the last 7 days: the cheapest settings that return the real page most of the time.
| Endpoint | /scrape |
|---|---|
js | true |
wait_for | 8000 |
| Cost | up to 5 credits a request |
| Learned | js + wait 8000 (found by our retry layer) |
For search and listing pages, change the query or the page parameter in the URL to paginate, and fetch the pages one after another rather than in bursts. Collect detail page URLs from listing pages first, then fetch each detail page. Our checks pass with JavaScript rendering on (js=true) and a wait of 8 seconds (wait_for=8000) before the snapshot: keep both.
Troubleshooting
The failures our own checks of youtube.com ran into over the last 7 days, and what got the page in the same check.
| What happened | Times | What fixed it |
|---|---|---|
| A different page than expected | 3 | None of the settings we tried got past it in 7 days. |
| The page did not load in time | 2 | Nothing we tried in the same check. Retry later, one request at a time. |
What people build with YouTube data
- Market researchFollow public company pages and job postings to see who grows and hires.More on this use case
Limits and etiquette
- Public pages only. Pages behind a login, and data shown only to signed-in users, are out of scope.
- Keep the rate modest: fetch pages one after another or with low concurrency, and cache what you already have.
- robots.txt of www.youtube.com (read 2026-11-17): public pages asked to stay away (Disallow: /results); no crawl delay set.
- Read YouTube's terms of service before you collect data at scale, and do not collect personal data you have no basis to process. This guide is not legal advice.
Questions
Can you scrape YouTube with Ujeebu?
Yes. 18 of 21 checks of public YouTube pages passed in the last 7 days with the settings on this page.
Which settings work for YouTube?
Call /scrape with js=true, wait_for=8000. Our retry layer found that this site needs "js + wait 8000".
How many credits does a YouTube request cost?
With these settings a request costs up to 5 credits. Only responses with HTTP 200 or 404 are billed: a blocked or timed-out request is free.
Which fields can I extract from YouTube?
With the extraction recipes on this page, validated on real YouTube pages through our API: search and listing pages: duration, image, published, title, url, views; detail pages: name, thumbnail, uploaded, description, image, url. Pass the recipe as extract_rules in a POST to /scrape and the API returns those fields as JSON.
Is it allowed to scrape YouTube?
Its robots.txt asks generic crawlers to stay away from public pages (Disallow: /results). Collect public pages only, read YouTube's terms of service, keep your request rate modest and do not collect personal data you have no basis to process. This is not legal advice.
How fresh is this page?
The status and settings come from our own health checks of youtube.com, which run around the clock. Last check: 2026-11-22 20:02:10 UTC; last pass: 2026-11-22 13:33:49 UTC.