YouTube 以三種方式阻擋逐字稿抓取,作者分享實測辨別方法
YouTube blocks transcript scrapers in three separate ways. Here's how I worked out which one I was hitting
作者根據 2026 年 11 月的實測,將 YouTube 逐字稿抓取失敗分為翻譯字幕 HTTP 429、音訊下載中途 HTTP 403,以及 IP 信譽觸發的 bot 驗證三類。
Disclosure: I built the tool this post is about, a YouTube transcript Actor on Apify. The findings below come from my own test runs in November 2026, and everything here is something I measured.
If you've ever pulled YouTube transcripts in bulk, you know how it goes: it works fine on your laptop, then fails on a server with a different error every day. I spent a week getting a transcript scraper to hold up, and the most useful thing I learned was this:
YouTube doesn't have one anti-scraping defense. It has several, each needs a different fix, and the wrong fix makes things more expensive without making them work.
Here are the three I hit, how I told them apart, and what fixed each one.
1. Translated captions: HTTP 429, even on a fresh IP
YouTube can translate any caption track (&tlang=fr). From an app client, those requests kept failing:
- From my home IP: 5 of 5 translation requests got HTTP 429. Plain captions for the same videos returned 200.
- From residential proxies with a fresh IP on every attempt: 5 of 7 still failed after 4 retries each.
A rate limit tied to the IP would have cleared on a fresh IP. This didn't, so the block is on the feature, not the IP. Retrying only tripled my proxy bill.
Fix: try YouTube's translation once with no retries. If it's refused, fetch the original track and translate it myself, line by line, so every timestamp stays exact. I send the lines as a numbered JSON object without the timestamps, then put the translated text back onto the original segments.
Something that bit me here: auto-captions are cut mid-sentence, and the model "helpfully" merged fragments and dropped lines. Strict JSON-schema output (every key required), batches of 40 lines, and re-asking any missing line together with its neighbors fixed that.
2. Audio downloads: 403 after the first ~300 KB
For videos with no captions at all, the only way to get a transcript is from the audio. With the keyless Android client, range requests up to ~256 KB worked, and anything past about 300 KB returned 403. That's roughly the first minute of audio.
That isn't an IP problem either: the same IP got the start of the file, so the block is on what that client is allowed to fetch.
Fix: rotate clients, not IPs. yt-dlp with a JavaScript runtime (--js-runtimes node) downloaded a full 14-minute talk using other client identities. Then Whisper (large-v3-turbo) turns the audio into timestamped text.
Two Whisper gotchas:
- On music or silence it invents text: a music-only news intro came back as "Thank you." three times. I filter stock phrases, near-zero words per second, repeats and high compression ratios. If nothing real is left, the result is marked "no speech" instead of returning made-up text.
- Running 4 downloads in parallel in 256 MB of memory killed the whole run. Cap your audio workers by memory.
3. "Sign in to confirm you're not a bot": IP reputation
After ~150 requests in a few hours, my home IP started getting the bot check on some videos. None of 20 runs on residential proxies (fresh IP per attempt) hit it. Datacenter proxies, on the other hand, got it on every audio download.
Fix: residential IPs and a fresh session per attempt. This is the only one of the three where switching IPs is the answer.
How to tell them apart
| Symptom | What it is | What works | What wastes money |
|---|---|---|---|
| 429 on translated captions only | Blocked per feature | Translate it yourself | Retrying on new IPs |
| 403 partway through an audio download | Blocked per client | Switch to a different client | New IPs |
| "Confirm you're not a bot" | IP reputation | Residential IP, fresh session | Retrying on the same IP |
My rule now: before changing anything, look at which request failed and what the same IP can still do.
- If the same IP still gets plain captions, IP reputation isn't your problem.
- If a fresh IP fails the same way, the block is on the feature or the client.
Cost, measured
- Captions only: about $0.0002–0.0014 per video on Apify. Most of it was compute, until I dropped the default memory from 4 GB to 256 MB, which made runs 7× cheaper and 4× faster.
- Audio fallback: about $0.004 per audio minute, mostly residential proxy traffic. Whisper itself was ~$0.0007 per minute.
Telling the user how each transcript was made
The other half of the work was output that never quietly gives you the wrong thing. Every result says where it came from (transcriptSource: captions or audio) and what happened with translation (translationStatus: youtube, ai, failed, ...). A failed video gets its own error code (LIVE_NOW, AUDIO_TOO_LONG, NO_SPEECH, ...). One surprise: some uploads have a caption track labeled English that's actually Spanish lyrics. Detecting the real language and flagging it (languageMismatch) has saved me more debugging time than anything else.
Try it
- Code examples (Python, Node, curl): https://github.com/luisholguindev0/youtube-transcript-examples
- The Actor: https://apify.com/luisbendeckdev/youtube-transcript-scraper. It's free during launch; you pay only Apify's platform usage. Audio transcription and AI translation need a paid Apify plan, and translation depends on the capacity of the AI provider behind it.
- For AI agents (MCP):
https://mcp.apify.com?tools=luisbendeckdev/youtube-transcript-scraper
If you only need captions and run from a home IP, the open-source youtube-transcript-api library may be all you need.
Questions welcome, especially if you've hit a fourth kind of block I haven't seen yet.
來源:DEV Community · dev.to