YouTube Subtitles
Learn how to scrape subtitles (closed captions) from YouTube videos using Web Scraper API. Find out more about its parameters and practical examples.
You can get YouTube subtitles and closed captions (CC) by providing the YouTube video ID and a language_code to the youtube_subtitles source.
Subtitles (closed captions) are separate from transcripts. To extract standard transcripts, use the YouTube Transcript source.
Request samples
The following example demonstrates how to retrieve English closed captions from a YouTube video where captions were provided by the uploader.
curl 'https://realtime.oxylabs.io/v1/queries' \
--user 'USERNAME:PASSWORD' \
-H 'Content-Type: application/json' \
-d '{
"source": "youtube_subtitles",
"query": "c4P_YuNnZ7U",
"context": [
{
"key": "language_code",
"value": "en"
},
{
"key": "subtitle_origin",
"value": "uploader_provided"
}
]
}'import requests
from pprint import pprint
# Structure payload.
payload = {
'source': 'youtube_subtitles',
'query': 'c4P_YuNnZ7U',
'context': [
{
'key': 'language_code',
'value': 'en'
},
{
'key': 'subtitle_origin',
'value': 'uploader_provided'
}
]
}
# Get response.
response = requests.request(
'POST',
'https://realtime.oxylabs.io/v1/queries',
auth=('username', 'password'),
json=payload,
)
# Print the JSON response with the result.
pprint(response.json())Our examples use Realtime integration method. If you would like to use Proxy Endpoint, or asynchronous Push-Pull integration, refer to the Integration Methods section.
Request parameter values
Generic
source
Sets the scraper.
youtube_subtitles
query
YouTube video ID.
–
context:
language_code
Specifies the language of the subtitles. Find available values here.
NOTE: If the provided language_code has no matching subtitles / closed captions in the YouTube video, the result returns a 404 status.
–
context:
subtitle_origin
Specifies whether to retrieve subtitles that are auto_generated or uploader_provided.
–
– mandatory parameter
Last updated
Was this helpful?

