How to Scrape a YouTube Video Transcript
YouTube transcripts give you the full context of a video—key topics, quotes, timestamps, and languages—without having to watch it end-to-end. By scraping transcripts, you can power search, analysis, content automation, and richer video insights instantly.
We're going to use a simple API by SerpApi: YouTube Video Transcript API.
Step-by-step on scraping a transcript from YouTube
Get your API Key
First, ensure you register at serpapi.com to get your API Key. You can get 250 free searches per month. You can use this API Key to access all of our APIs, including the YouTube Video Transcript API.
cURL Implementation
Here is the basic implementation in cURL:
curl --get https://serpapi.com/search \
-d engine="youtube_video_transcript" \
-d v="Gk8gB5VACZw" \
-d type="asr" \
-d api_key="API_KEY"Parameter explanation:
v: is the video ID, which can be found from the URL or using our YouTube Search API
type : Parameter is used to get the transcript type. E.g: asr for an automatic speech recognition (auto-generated) transcript.
Warning: Some videos only have automatic speech recognition.
Available parameters
In addition to running the basic search, you can view all our available parameters here.
For example, we provide language_code to define the language for the transcript when it's available.
When performing the original request, you can see all the available_transcripts on the response:
Python tutorial
Next, let's see how to scrape the YouTube video transcript search results in Python.
Preparation for accessing the SerpApi API in Python
- Create a new
main.pyfile - Install requests with:
pip install requestsHere is what the basic setup looks like:
import requests
SERPAPI_API_KEY = "YOUR_REAL_SERPAPI_API_KEY"
params = {
"api_key": SERPAPI_API_KEY, #replace with your real API Key
# soon
}
search = requests.get("https://serpapi.com/search", params=params)
response = search.json()
print(response)With these few lines of code, we can access all of the search engines available at SerpApi, including the YouTube Video Transcript API.
import requests
SERPAPI_API_KEY = "YOUR_SERPAPI_API_KEY"
params = {
"api_key": SERPAPI_API_KEY,
"engine": "youtube_video_transcript",
"v": "Gk8gB5VACZw",
"type": "asr",
}
search = requests.get("https://serpapi.com/search", params=params)
response = search.json()
print(response)To make it easier to see the response, let's add indentation to the output.
import json
# ...
# ...
# all previous code
print(json.dumps(response, indent=2))Running this Python file should show you the transcripts from a YouTube video.
Print specific items
Let's say we only want to print the snippet(text) and the start time. We can loop the transcript response like this:
for result in response.get("transcript", []):
snippet = result.get("snippet")
start_time_text = result.get("start_time_text")
print(f"Snippet: {snippet}")
print(f"start_time_text: {start_time_text}")
print("-" * 10)
JavaScript tutorial
Next, let's see how we can do this in JavaScript.
Install the serpapi package:
npm install serpapiRun a basic query:
const { getJson } = require("serpapi");
getJson({
engine: "youtube_video_transcript",
api_key: API_KEY, // Put your API Key
v: "Gk8gB5VACZw",
type: "asr",
}, (json) => {
console.log(json["locations"]);
});Other programming languages
While you can use our APIs using a simple GET request with any programming language, you can also see our ready-to-use libraries here: SerpApi Integrations.
Available data from the YouTube Video Transcript API
Aside from the text itself, we can check the start and end time of each text in milliseconds.
We also provide video chapters to scrape:
You can learn how to scrape YouTube search results here:
You can also scrape YouTube videos data and their comments:
Frequently Asked Questions (FAQs)
Is it legal to scrape the YouTube Transcript?
Scraping publicly available data from websites like YouTube transcripts is generally permitted under U.S. law.
How much does it cost?
Register at serpapi.com to start for free. If you want to scale, we offer tiered plans based on your usage.
Why do you need to scrape YouTube Transcript from a video?
Scraping YouTube transcripts from videos serves various purposes, including content analysis for research, improving accessibility for individuals who are deaf or hard of hearing, and enhancing search engine optimization (SEO) for better discoverability. Marketers and content creators can repurpose video content into articles or social media snippets by leveraging transcripts, and researchers, academics, and students might collect them for projects or analyses. Additionally, language learners can use transcripts to improve comprehension and vocabulary while watching videos, and businesses may need them for record-keeping or compliance.