[Home](https://scrapfly.io/)/[Scrapers](https://scrapfly.io/scrapers)/YouTube

Videos · transcripts · comments · channels · search

# // YouTube Scraper API

Get YouTube video, transcript, comment, channel and search data as JSON. Requests go out from residential IPs, so YouTube returns the page instead of “Sign in to confirm you’re not a bot”.

- **Open-source scraper, tested against live YouTube every night.** One Python file covers videos, comments, channels, channel video lists, search and Shorts.
- **No selectors to break.** YouTube embeds each video's data as JSON in the page, and the scraper reads that JSON directly.
 
 [Get free API key](https://scrapfly.io/register) [View GitHub scraper](https://github.com/scrapfly/scrapfly-scrapers/tree/main/youtube-scraper) [Read proxy docs](https://scrapfly.io/docs/scrape-api/proxy) 

1,000 free credits. No credit card required.

 [](https://www.capterra.com/p/212653/Scrapfly/)★★★★★4.9/5 from 236 reviews

 

 

 Any YouTube video page

 

 

 Video JSON**Output**

```
{
  <span class="c-str">"video"</span>: {
    <span class="c-str">"videoId"</span>: <span class="c-str">"x7X9w_GIm1s"</span>,
    <span class="c-str">"title"</span>: <span class="c-str">"Python in 100 Seconds"</span>,
    <span class="c-str">"publishingDate"</span>: <span class="c-str">"Oct 25, 2021"</span>,
    <span class="c-str">"stats"</span>: {
      <span class="c-str">"viewCount"</span>: <span class="c-num">3108034</span>,
      <span class="c-str">"likeCount"</span>: <span class="c-num">116000</span>, <span class="c-str">"commentCount"</span>: <span class="c-num">1700</span>
    }
  },
  <span class="c-str">"channel"</span>: {<span class="c-str">"name"</span>: <span class="c-str">"Fireship"</span>, <span class="c-str">"id"</span>: <span class="c-str">"@Fireship"</span>}
}
```

[YouTube scraper](https://github.com/scrapfly/scrapfly-scrapers/tree/main/youtube-scraper) · scrape\_video()[See the request ↓](#implementation)

  

What you can scrape from YouTube

Five kinds of YouTube data you can scrape with Scrapfly. The tags are field names from the JSON you get back.

 ## // Scrape YouTube video and Shorts data

Title, description, keywords, length, publish date, thumbnails, and view, like and comment counts for any public video, with the channel's name, handle, verified badge and subscriber count. Shorts carry the same video JSON.

- videoId
- title
- lengthSeconds
- keywords
- stats.viewCount
- channel.subscriberCount

  ## // Scrape YouTube transcripts

Every caption line with its start and end time, for videos that have captions. Render the watch page, click “Show transcript” with a JavaScript scenario, and the response carries YouTube's own transcript request.

- startMs
- endMs
- snippet.runs.text
- browser\_data.xhr\_call

  ## // Scrape YouTube comments

Comment text, author, publish time, like count and reply count. Comments load from YouTube's internal comments endpoint one page at a time, each with a token for the next, so you collect as many pages as you need.

- comment.text
- author.displayName
- publishedTime
- stats.likeCount
- stats.replyCount

  ## // Scrape YouTube channels

Description, subscriber, video and view counts, join date, country and external links from the channel's About panel, plus its video list sorted by Latest, Popular or Oldest.

- subscriberCount
- videoCount
- joinedDate
- country
- links
- description

  ## // Scrape YouTube search results

Video ID, title, snippet, length, views, publish time and badges for a search query. To apply the filters you would set on the site, copy the `sp` value from YouTube's search URL into `search_params`.

- id
- title
- videoLength
- viewCount
- publishedTime
- channelBadges

  



Reliability

## // Get past YouTube's bot check

YouTube decides by IP address. On datacenter IPs, every watch page in our test came back as “Sign in to confirm you’re not a bot”, with HTTP 200 and no video data. Two settings and one check handle it.

`proxy_pool="residential"`Sends the request from a residential IP, the one thing that changed the result in our runs. The open-source scraper sets it on every watch, channel and Shorts page.



`playabilityStatus`The bot check returns HTTP 200, so the status code won't tell you. Read `playabilityStatus.status` in the page's JSON and retry when it says `LOGIN_REQUIRED`.



`country="US"`Sets the proxy country, and YouTube sets the page region from it: with `country="DE"` our request came back with region DE. Use it when you need another country's view of YouTube.



 



Choose your tools

## // Scrapfly products for YouTube scraping

Scrapfly's YouTube scraping API is the Web Scraping API on the residential pool, and most jobs need nothing else. Add the others for prompt-based extraction, screenshots, browser sessions or URL lists. One API key covers all of them.

 ### Web Scraping API for YouTube pages

Fetch watch, channel and Shorts pages with the proxy pool, rendering and country set per request.

YouTube embeds the video data as JSON in `ytInitialPlayerResponse`, so one fetch covers title, views, length and channel without selectors.

 

```
GET /scrape?url=https://www.youtube.com/watch?v=x7X9w_GIm1s&unblocker=true&render_js=true&proxy_pool=residential&country=US
```

 [Explore Web Scraping API →](https://scrapfly.io/products/web-scraping-api)  ### Data Extraction API for YouTube video fields

Name the fields in plain words with `extraction_prompt`. In three runs it returned the title, channel, view count, like count and upload date from the rendered watch page.

Also works on YouTube HTML you already saved, without a new fetch.

 

```
GET /scrape?url=https://www.youtube.com/watch?v=x7X9w_GIm1s&unblocker=true&render_js=true&wait_for_selector=ytd-watch-metadata&proxy_pool=residential&country=US&extraction_prompt=video+title,+channel+name,+view+count,+like+count,+upload+date
```

 [Explore Data Extraction API →](https://scrapfly.io/products/extraction-api)  ### Screenshots of YouTube pages

Add `screenshots[main]=fullpage` to the Web Scraping API request for a record of what the page showed: title, view count, channel.

Wait for `ytd-watch-metadata` first. Without it, our capture was YouTube's grey loading skeleton.

 

```
GET /scrape?url=https://www.youtube.com/watch?v=x7X9w_GIm1s&render_js=true&wait_for_selector=ytd-watch-metadata&proxy_pool=residential&country=US&screenshots[main]=fullpage
```

 [Read the screenshot docs →](https://scrapfly.io/docs/scrape-api/screenshot)  ### Cloud Browser API for YouTube sessions

Point your Playwright or Puppeteer script at a hosted browser when the job needs clicks: opening a channel's About panel, expanding a description, scrolling comments.

Put the residential pool on the connection URL so the whole session runs from a residential IP.

 

```
chromium.connect_over_cdp("wss://browser.scrapfly.io?key=KEY&proxy_pool=residential&country=us")
```

 [Explore Cloud Browser API →](https://scrapfly.io/products/cloud-browser-api)  ### Crawler API for YouTube URL lists

Submit a list of video URLs as one job. The proxy pool and [Unblocker](https://scrapfly.io/products/unblocker) (formerly ASP) settings apply to every URL, and you collect the pages when the job finishes.

- url\_list
- proxy\_pool
- unblocker
- content\_formats

 [Explore Crawler API →](https://scrapfly.io/products/crawler-api)  



One request

## // Fetch a YouTube video and read its JSON

The JSON at the top comes from the full scraper. This is the core of its watch-page request: one fetch, then the video fields read from the page's own JSON, with no selectors to write.

**Prefer the full scraper?** The open-source [YouTube scraper on GitHub](https://github.com/scrapfly/scrapfly-scrapers/tree/main/youtube-scraper) covers videos, comments, channels, channel video lists, search and Shorts in Python 3.10 and runs against live YouTube every night. Clone it, set `SCRAPFLY_KEY`, and run `poetry run python run.py`.

 

 Python · scrapfly-sdkscrape + parse

```
<span class="c-key">import</span> json
<span class="c-key">from</span> scrapfly <span class="c-key">import</span> ScrapeConfig, ScrapflyClient

client = ScrapflyClient(key=<span class="c-str">"YOUR_SCRAPFLY_KEY"</span>)
result = client.scrape(ScrapeConfig(
  <span class="c-str">"https://www.youtube.com/watch?v=x7X9w_GIm1s"</span>,
  unblocker=<span class="c-key">True</span>,  <span class="c-com"># previously asp</span>
  proxy_pool=<span class="c-str">"residential"</span>,
  country=<span class="c-str">"US"</span>, render_js=<span class="c-key">True</span>,
))
page = result.content
start = page.index(<span class="c-str">"{"</span>, page.index(<span class="c-str">"var ytInitialPlayerResponse"</span>))
player = json.JSONDecoder().raw_decode(page, start)[<span class="c-num">0</span>]
<span class="c-key">if</span> player[<span class="c-str">"playabilityStatus"</span>][<span class="c-str">"status"</span>] == <span class="c-str">"LOGIN_REQUIRED"</span>:
  <span class="c-key">raise</span> RuntimeError(<span class="c-str">"YouTube served its bot check, retry the request"</span>)
video = player[<span class="c-str">"videoDetails"</span>]
```

 

 



What the data is used for

## // Common YouTube scraping use cases

### Channel tracking

Record subscriber, video and view counts per channel on a schedule, and pick up new uploads from the Latest sort.



### Comment analysis

Collect comments with like and reply counts for sentiment, product feedback and moderation review.



### Search rank tracking

Record which videos appear for a query, in what order, with views and publish time.



### Creator research

Vet channels by subscriber count, join date, country and the links on their About panel.



### Content research

Compare titles, keywords, lengths and view counts across a topic or a set of competing channels.



### AI datasets

Build text datasets from titles, descriptions, transcripts and comments, with the source video ID on every row.



 



Common questions

## // YouTube scraping FAQ

 Is scraping YouTube legal?There is no universal answer. Legality depends on your jurisdiction, the data, the access method and how you use the result. Keep the workflow to public pages, avoid signed-in and private content, treat commenter names as personal data, review YouTube's terms, and get legal advice for commercial use.

 Do I need a YouTube API key or Google account?No. Scrapfly reads public pages signed out, so there is no Google API key, OAuth or YouTube account to manage. You only need a Scrapfly API key.

 Why do I get “Sign in to confirm you’re not a bot” when scraping YouTube?That is YouTube's IP check. In our test it hit every request from a datacenter IP, with HTTP 200 and no video data. Set `proxy_pool` to `residential`, then read `playabilityStatus` in the response and retry when it says `LOGIN_REQUIRED`.

 Can I scrape YouTube transcripts?Yes, for any video with captions. Render the watch page with the Web Scraping API and add a JavaScript scenario that clicks “Show transcript”. YouTube then loads the full timed transcript, and the response returns that request's JSON in `browser_data.xhr_call`. In our runs, all 72 caption lines of a 2:23 video came back every time, for 30 credits.

 How do I scrape all the comments on a video?Comments load from YouTube's internal comments endpoint one page at a time, each page with a token for the next, so you follow the tokens as far as you need. Every comment comes with its like and reply counts. The open-source scraper does this for you, with `max_scrape_pages` to cap the run.

 Are view and like counts exact?Yes. The view count in the page's JSON is exact. The like button shows a rounded label (116K), and the page also carries the exact number in its accessibility text (116,399 in our run). The open-source scraper reads the rounded label, which is why the example above shows `116000`.

 How much does scraping YouTube cost?In our runs, a YouTube watch page cost 30 credits on the residential pool with rendering, 25 without rendering. An extraction prompt added 20. Every account starts with 1,000 free credits.

 What are the rate limits when scraping YouTube?Scrapfly sets no YouTube-specific limit. Your maximum parallelism is the concurrency quota on your plan, or a lower cap configured for the project. Each in-flight request uses one slot until it finishes.

 



Start with one request

## Fetch the watch page. Read the video JSON.

Web Scraping API on the residential pool, one call per video.

Proxies across 190+ countries

 [YouTube scraper on GitHub](https://github.com/scrapfly/scrapfly-scrapers/tree/main/youtube-scraper) [How to scrape YouTube in Python](https://scrapfly.io/blog/posts/how-to-scrape-youtube) [All scraper pages](https://scrapfly.io/scrapers) 

 

 [Get free API key](https://scrapfly.io/register) [Read the docs](https://scrapfly.io/docs/scrape-api/proxy)