Scrape YouTube search results, video metadata, and subtitles as JSON with the ScrapingBee YouTube scraping API. This is a developer cookbook. Each section is one task with copy-paste code, and ScrapingBee runs the proxies, the headless browser, and the parsing for you. If you want a YouTube scraper that returns clean data instead of a JavaScript shell, the recipes below cover it.
Grab a free key (1,000 credits, no card) at scrapingbee.com. Every request authenticates with a Bearer token:
-H "Authorization: Bearer YOUR_API_KEY"
Three endpoints, all returning JSON:
| Task | Endpoint | Credits |
|---|---|---|
| Search videos, channels, playlists | /api/v1/youtube/search |
5 |
| Full metadata for one video | /api/v1/youtube/metadata |
see request builder |
| Timestamped captions | /api/v1/youtube/subtitles |
see request builder |
Full reference: YouTube API documentation.
The search endpoint is the core of any YouTube video scraper. Pass a query, get back results with titles, channels, view counts, durations, and thumbnails.
cURL:
curl "https://app.scrapingbee.com/api/v1/youtube/search?search=python%20tutorial" \
-H "Authorization: Bearer YOUR_API_KEY"Python:
import requests
response = requests.get(
url="https://app.scrapingbee.com/api/v1/youtube/search",
headers={"Authorization": "Bearer YOUR_API_KEY"},
params={"search": "python tutorial"},
)
print(response.json())Node.js:
const axios = require('axios');
axios.get('https://app.scrapingbee.com/api/v1/youtube/search', {
headers: { Authorization: 'Bearer YOUR_API_KEY' },
params: { search: 'python tutorial' },
}).then((response) => console.log(response.data));Add filters to focus the search. type is one of video, channel, playlist, movie. duration is one of <4, 4-20, >20. sort_by is one of rating, relevance, view_count, upload_date.
params = {
"search": "machine learning",
"type": "video",
"upload_date": "this_month",
"duration": "4-20",
"sort_by": "view_count",
"hd": "true",
}Fetch full details for a single video by its id. This is how you turn a list of video ids into a structured YouTube data scraper dataset with view counts, durations, and descriptions.
import requests
response = requests.get(
url="https://app.scrapingbee.com/api/v1/youtube/metadata",
headers={"Authorization": "Bearer YOUR_API_KEY"},
params={"video_id": "dQw4w9WgXcQ"},
)
print(response.json())The response includes duration, view count, like count, upload date, description, channel info, thumbnails, and available formats.
Download timestamped captions for a video. Use subtitle_origin to pick auto-generated or uploader-provided captions when both exist.
import requests
response = requests.get(
url="https://app.scrapingbee.com/api/v1/youtube/subtitles",
headers={"Authorization": "Bearer YOUR_API_KEY"},
params={"video_id": "dQw4w9WgXcQ", "language": "en"},
)
print(response.json())Subtitle text feeds summarization, on-page search, and RAG ingestion pipelines.
| Parameter | Type | Default | Values |
|---|---|---|---|
search |
string | required | search terms |
type |
string | "" | video, channel, playlist, movie |
upload_date |
string | "" | today, last_hour, this_week, this_month, this_year |
duration |
string | "" | <4, 4-20, >20 |
sort_by |
string | relevance |
rating, relevance, view_count, upload_date |
hd |
bool | false | true / false |
4k |
bool | false | true / false |
subtitles |
bool | false | true / false |
creative_commons |
bool | false | true / false |
live |
bool | false | true / false |
tag |
string | "" | custom id echoed back in the response |
Other documented flags: 360, 3d, hdr, vr180, location, purchased.
A search response:
{
"results": [
{
"videoId": "...",
"title": { },
"longBylineText": { },
"thumbnail": { },
"lengthText": { },
"shortViewCountText": { },
"publishedTimeText": { }
}
],
"search": "query string"
}Each result populates only the fields YouTube returned, so null-check before reading.
ScrapingBee bills successful calls. YouTube search costs 5 credits per call. Metadata and subtitles costs appear next to the "Try it" button in the dashboard request builder. See ScrapingBee pricing for plan tiers.
Is there a free YouTube scraper API? ScrapingBee gives 1,000 free credits at signup with no card. Search is 5 credits per call, so the trial covers a few hundred queries.
How do I pull a transcript?
Call the subtitles endpoint with the video_id. It returns timestamped caption segments, and subtitle_origin selects auto-generated or uploader-provided captions.
Can I filter by upload date, duration, or quality?
Yes. Use upload_date, duration, and flags like hd and 4k.
Is scraping YouTube legal? Public data is generally collectible for research and monitoring, but YouTube's terms and local regulations apply. Scrape public content only.
MIT