# YouTube Search Scraper (`datahamster/youtube-search-scraper`) Actor

YouTube search scraper with no API key and no login: videos, Shorts, channels or playlists for any keyword, with views, duration, upload date, channel and position. Filters for type, upload date, duration and popularity. Monitor mode alerts on new videos for a saved search.

- **URL**: https://apify.com/datahamster/youtube-search-scraper.md
- **Developed by:** [Viktor Dubnytskiy](https://apify.com/datahamster) (community)
- **Categories:** Videos, Social media
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.80 / 1,000 result items

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## YouTube Search Scraper

Search YouTube by keyword and get one flat row per result: video id, URL, title, channel, views, duration, upload
date, live and Shorts flags, thumbnail and position in the results. No API key, no quota, no login. The actor asks
YouTube search the same way a logged-out visitor does, with YouTube's own filters for type, upload date, duration
and popularity.

**Try it:** the prefilled example returns 20 rows in about 5 seconds and costs about $0.07. Results cost $3.50 per 1,000.

### What you get

Real rows from the example dataset (the prefilled run, `queries: ["python tutorial"]`, 20 rows):

| position | title | channel | views | duration | published |
|---|---|---|---|---|---|
| 1 | Python Full Course for free 🐍 | Bro Code | 13,252,030 | 12:00:00 | 2 years ago |
| 2 | Python for Beginners - Learn Coding with Python in 1 Hour | Programming with Mosh | 25,801,817 | 1:00:06 | 6 years ago |
| 3 | Learn Python in Less than 10 Minutes for Beginners (Fast & Easy) | Indently | 1,892,308 | 10:30 | 5 years ago |
| 4 | Python Tutorial for Beginners - Learn the basics in 20 Min | Tech With Tim | 89,456 | 19:39 | 3 months ago |
| 5 | Python Full Course for Beginners | Programming with Mosh | 49,502,073 | 6:14:07 | 7 years ago |

Full row: `id`, `url`, `resultType` (`video`, `short`, `channel`, `playlist`), `videoId`, `title`, `channelName`,
`channelId`, `channelUrl`, `channelHandle`, `publishedText`, `publishedAt`, `viewCountText`, `viewCount`,
`durationSeconds`, `isLive`, `isShort`, `thumbnailUrl`, `descriptionSnippet`, `badges`, `playlistId`, `videoCount`,
`subscriberCount`, `query`, `position`, `scrapedAt`.

Rows describe public videos and the channel that uploaded them. Nothing about viewers or commenters is collected.

### Use cases

- **Keyword research for creators and marketers.** See what ranks for a phrase, who made it, how many views it has
  and how long it is, for many phrases in one run.
- **Brand and competitor watch.** Save a search for your brand or product name in monitor mode and get only the new
  videos on every run, by webhook or Telegram.
- **Lead lists of channels in a niche.** Switch the type to Channels and get channel names, handles and subscriber
  counts for a topic.
- **Fresh content feeds.** Combine a query with Upload date "Today" or "Last hour" for a live feed of new uploads.

### Try it in 10 seconds

**One-off search.** Press **Start**: the prefilled input searches `python tutorial` and returns the top 20 videos.

**Monitor mode.** Save a task with this input and put it on a schedule (Apify, Schedules, e.g. daily):

```json
{
  "mode": "monitor",
  "monitorStateId": "brand-watch",
  "queries": ["your brand name"],
  "uploadDate": "week",
  "webhookUrl": "https://your-endpoint.example.com/hook"
}
```

Each monitor run charges one `monitor-check` event and returns only videos that were not in the previous run's
results, each billed as one `change` event. Monitor mode compares video ids only, so a view count moving on a known
video does not count as a change.

### Related actors

- [YouTube Transcript Scraper](https://apify.com/datahamster/youtube-transcript-scraper): the full transcript of
  every video you found.
- [YouTube Comments Scraper](https://apify.com/datahamster/youtube-comments): comment texts and like counts for a
  list of videos.
- [YouTube Channel Monitor](https://apify.com/datahamster/youtube-channel-monitor): watch a fixed list of channels
  for new uploads.
- [YouTube Shorts Scraper](https://apify.com/datahamster/youtube-shorts): every Short on a channel's Shorts tab.

### Input

| Field | Meaning | Default |
|---|---|---|
| `queries` | Search phrases, one per line | `["python tutorial"]` |
| `type` | `video`, `shorts`, `channel` or `playlist` | `video` |
| `uploadDate` | `any`, `hour`, `today`, `week`, `month`, `year` | `any` |
| `duration` | `any`, `short` (under 3 min), `medium` (3 to 20 min), `long` (over 20 min) | `any` |
| `sortBy` | `relevance` or `views` (YouTube's "Popularity") | `relevance` |
| `maxItemsPerQuery` | Rows per query, 1 to 1000 | `50` (prefilled 20) |
| `maxItems` | Rows per run in total | `200` (prefilled 20) |
| `strictQueryMatch` | Drop YouTube's filler rows for a query it found nothing for | `true` |
| `tier`, `proxyCountry` | Proxy tier (auto climbs only on a bot check) and region | `auto`, `US` |
| `mode`, `monitorStateId`, `webhookUrl`, `telegramBotToken`, `telegramChatId` | Monitor mode and alerts | `scrape` |

### How it works

1. Each query is sent to YouTube search with the filters you picked, encoded exactly as YouTube's own filter menu
   encodes them.
2. Further pages follow the results list's own "load more" continuation until the list ends, every result was
   already seen, or `maxItemsPerQuery` is reached.
3. If YouTube answers with a bot check, the request is retried on a stronger proxy tier. A run where every request
   was refused ends as **blocked**, never as an empty "no results".

### Pricing

| Event | Price |
|---|---|
| result | $0.0035 per row ($3.50 per 1,000) |
| monitor-check | $0.005 per monitor run |
| change | $0.0035 per new video in monitor mode |

Store discounts: SILVER plan -10%, GOLD and above -20% on every event.

You pay only for rows that are pushed. Filler rows dropped by `strictQueryMatch` are never pushed and never charged. Platform usage is billed by Apify on top. Most runs need no proxy at all.

### Limits

- `viewCount` is exact on video rows. On Shorts grid rows YouTube shows a rounded figure ("1.7M views") and no
  channel, so those fields are rounded or empty.
- `publishedAt` is computed from YouTube's relative label ("13 hours ago") and is approximate. Labels in months or
  years are too coarse, so `publishedAt` stays empty and `publishedText` keeps the label.
- Live streams show "N watching" instead of a view count, so `viewCount` is empty and `isLive` is true.
- YouTube removed sorting by upload date and by rating from its search. Use the Upload date filter for fresh videos.
- For a typo or a nonsense query YouTube searches a "corrected" query and pads the list with unrelated videos. With
  `strictQueryMatch` on (the default) only rows containing a word of your query are kept, which can mean zero rows;
  the query is then listed under `skippedQueries` in the run's `ADAPTER_STATS` record.

### FAQ

**Does it need a YouTube API key or account?** No. The actor never asks for a YouTube login, cookies or an API key.
The only token field is the optional Telegram bot token for monitor-mode alerts.

**Why did a run return nothing?** The `RUN_SUMMARY` record in the run's key-value store has `emptyReason`. A bot
check is reported as `blocked`, an empty search as `no_matches`.

### Changelog

- 0.1: initial release. Keyword search for videos, Shorts, channels and playlists with YouTube's type, upload date,
  duration and popularity filters, continuation paging, filler filter (`strictQueryMatch`), proxy ladder on a bot
  check, monitor mode for new videos.

***

If this actor saved you time, a short review on its Store page helps other people find it. Missing a field? Open an
issue on the **Issues** tab.

# Actor input Schema

## `queries` (type: `array`):

What to type into YouTube search, one query per line, e.g. "python tutorial". Each query is searched separately and its rows carry the query and their position.

## `type` (type: `string`):

YouTube's own Type filter. Videos is the default; Shorts returns only Shorts; Channels and Playlists return channel or playlist rows instead of videos.

## `uploadDate` (type: `string`):

YouTube's Upload date filter, e.g. "week" for videos uploaded in the last 7 days. Applies to videos and Shorts.

## `duration` (type: `string`):

YouTube's Duration filter. Applies to videos.

## `sortBy` (type: `string`):

YouTube's Prioritize setting: relevance (default) or popularity. YouTube removed the old upload-date and rating sorts from its search; use the Upload date filter for fresh videos.

## `maxItemsPerQuery` (type: `integer`):

Stop each query after this many rows, e.g. 100. One page holds about 20 results; further pages follow YouTube's own continuation until the list ends.

## `strictQueryMatch` (type: `boolean`):

true = when YouTube finds nothing for the query as typed and pads the list with unrelated videos ("Showing results for ..."), keep only rows whose title, description or channel contains a word of the query, so filler is never pushed or charged. false = keep everything YouTube returns.

## `tier` (type: `string`):

auto starts without a proxy and moves to datacenter, then residential, only when YouTube answers with a bot check. Pin a tier to force it.

## `proxyCountry` (type: `string`):

Two-letter country for YouTube's regional results and the proxy exit, e.g. "US" or "DE".

## `maxItems` (type: `integer`):

Stop the whole run after this many rows, across all queries (you are charged only for pushed rows).

## `mode` (type: `string`):

scrape = full results; monitor = only new/changed items since the previous run of this task

## `monitorStateId` (type: `string`):

Optional state id when not running as a saved task (monitor mode)

## `webhookUrl` (type: `string`):

POST a change summary here in monitor mode

## `telegramBotToken` (type: `string`):

Optional: bot token for monitor-mode change summaries

## `telegramChatId` (type: `string`):

Optional: chat id that receives monitor-mode summaries

## Actor input object example

```json
{
  "queries": [
    "python tutorial"
  ],
  "type": "video",
  "uploadDate": "any",
  "duration": "any",
  "sortBy": "relevance",
  "maxItemsPerQuery": 20,
  "strictQueryMatch": true,
  "tier": "auto",
  "proxyCountry": "US",
  "maxItems": 20,
  "mode": "scrape"
}
```

# Actor output Schema

## `results` (type: `string`):

All pushed rows (dataset, JSON)

## `resultsTable` (type: `string`):

Dataset in the Console viewer

## `runSummary` (type: `string`):

RUN_SUMMARY record

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "queries": [
        "python tutorial"
    ],
    "maxItemsPerQuery": 20,
    "maxItems": 20
};

// Run the Actor and wait for it to finish
const run = await client.actor("datahamster/youtube-search-scraper").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "queries": ["python tutorial"],
    "maxItemsPerQuery": 20,
    "maxItems": 20,
}

# Run the Actor and wait for it to finish
run = client.actor("datahamster/youtube-search-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "queries": [
    "python tutorial"
  ],
  "maxItemsPerQuery": 20,
  "maxItems": 20
}' |
apify call datahamster/youtube-search-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,datahamster/youtube-search-scraper"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/1ktdkE8jVJPAJuQR6/builds/4JtBHdDdkieCINOyd/openapi.json
