# YouTube Posts (Videos) Search Scraper (`outspoken_strategy/youtube-post-search-scraper`) Actor

Search YouTube videos by keyword. Multiple keywords, sort by upload date/relevance/views/rating, upload-date and date-range filters, auto-pagination. Returns title, description, channel, views, duration and thumbnails. No login needed.

- **URL**: https://apify.com/outspoken\_strategy/youtube-post-search-scraper.md
- **Developed by:** [code craker](https://apify.com/outspoken_strategy) (community)
- **Categories:** Social media, News, E-commerce
- **Stats:** 3 total users, 2 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $5.00 / 1,000 results

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

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

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## YouTube Posts (Videos) Search Scraper

Apify actor that searches YouTube videos by keyword and exports them as structured
data — no login, no cookies, no YouTube API quota.

It parses the `ytInitialData` JSON embedded in the search results page and paginates
through YouTube's own InnerTube `/youtubei/v1/search` continuation API. Requests go
over plain HTTP first (fast and cheap); if YouTube blocks that (captcha/"unusual
traffic" on flagged IPs), the actor automatically escalates to a real Chrome browser
for the rest of the run — continuation requests then run inside the page as
same-origin fetches.

### Features

- One keyword (`query`) or many (`queries`) — each searched separately, results
  combined and de-duplicated by video.
- Sort by `date` (newest first), `relevance`, `views` or `rating` — encoded into
  YouTube's `sp` filter parameter, results restricted to videos (no channels,
  playlists or shorts shelves).
- YouTube's own upload-date window (`uploadDate`: hour/today/week/month/year) plus
  approximate `timeSince` / `timeUntil` bounds enforced actor-side.
- Auto-pagination until `numberOfVideos` per keyword is reached or the feed dries up
  (YouTube stops serving search results after roughly 500-600 per query).
- Results are pushed page by page, so an abort or timeout keeps everything collected
  so far.
- Automatic block recovery: fresh proxy IP on each retry, plain HTTP → real Chrome
  escalation, EU consent interstitial bypassed via cookies.
- When a run ends with 0 results, the last page fetched is saved as `DEBUG_HTML` in
  the run's key-value store.

### Input

```json
{
    "queries": ["econet", "delta corporation"],
    "sort": "date",
    "numberOfVideos": 100,
    "uploadDate": "month",
    "proxyConfiguration": {
        "useApifyProxy": true,
        "apifyProxyGroups": ["RESIDENTIAL"],
        "apifyProxyCountry": "US"
    }
}
````

`numberOfVideos` applies **per keyword**.

### Output

One dataset item per video:

```json
{
    "id": "XXaUd0fGpOs",
    "url": "https://www.youtube.com/watch?v=XXaUd0fGpOs",
    "title": "Artificial Intelligence: Complete path to 2030",
    "description": "Search snippet of the video description...",
    "channelName": "Future Business Tech",
    "channelId": "UCGBO6EahCqQSyXIws1MQdDg",
    "channelUrl": "https://www.youtube.com/@FutureBusinessTech",
    "publishedTimeText": "1 day ago",
    "created_at": "2026-07-08T09:15:00.000Z",
    "viewCount": 29547,
    "viewCountText": "29,547 views",
    "duration": "2:02:04",
    "durationSeconds": 7324,
    "thumbnail": "https://i.ytimg.com/vi/XXaUd0fGpOs/hq720.jpg",
    "isLive": false,
    "searchQuery": "artificial intelligence",
    "sort": "date",
    "uploadDate": "all"
}
```

- `created_at` is APPROXIMATE: YouTube search only exposes relative publish times
  ("3 weeks ago"), which we convert against the scrape time. `publishedTimeText`
  keeps the raw value. Live/upcoming items have `created_at: null`.
- `description` is the search snippet, not the full video description.

### Integration (scraping-tool)

Call it like the other `outspoken_strategy/*` search actors:

```js
const res = await this.scrapingService.scrape({
    url: `https://www.youtube.com/results?search_query=${encodeURIComponent(keyword)}`,
    resultsLimit: requestCount,
    actor: 'outspoken_strategy/youtube-post-search-scraper',
    timeout,
    additionalInput: {
        query: keyword,
        numberOfVideos: requestCount,
        sort: 'date',
        proxyConfiguration: { useApifyProxy: true, apifyProxyGroups: ['RESIDENTIAL'], apifyProxyCountry: 'US' }
    },
    scrapeType: 'youtube-keyword-search'
});
```

Normalization hints: `url` and `id` are ready to use; index `title + description`
for relevance matching; `viewsCount` ← `viewCount`, `createdTime` ← `created_at`
(approximate), author fields are `channelName` / `channelId` / `channelUrl`.

### Local development

```bash
npm install
echo '{ "query": "artificial intelligence", "numberOfVideos": 50, "proxyConfiguration": { "useApifyProxy": false } }' > storage/key_value_stores/default/INPUT.json
npm start
```

Deploy with `apify push`.

# Actor input Schema

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

One keyword/phrase to search for. Wrap in double quotes for an exact phrase match, e.g. "econet revenue". You can also paste several keywords, one per line, to search them all. For a clean list use the "queries" field below instead. Leave empty if you use "queries".

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

Multiple keywords/phrases to search — each is searched separately and results are combined and de-duplicated by video. Takes precedence over/adds to "query". numberOfVideos applies PER keyword.

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

How YouTube orders the search results: "date" (newest first), "relevance", "views" or "rating".

## `numberOfVideos` (type: `integer`):

Maximum number of videos to fetch per keyword. YouTube search stops serving results after roughly 500-600 per query.

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

YouTube's own upload-date window for the search (the "Upload date" filter dropdown).

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

Only return videos published on or after this date (format: yyyy-mm-dd). APPROXIMATE: search results only expose relative publish times ("3 weeks ago"), so the comparison uses the derived created\_at. Combine with the uploadDate filter for hard cutoffs.

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

Only return videos published before this date (format: yyyy-mm-dd). APPROXIMATE — see timeSince.

## `proxyConfiguration` (type: `object`):

Proxy to route traffic through. Residential proxies are recommended — YouTube captchas or blocks flagged datacenter IPs.

## `headless` (type: `boolean`):

The actor fetches over plain HTTP and only falls back to a Chrome browser when YouTube blocks it. Uncheck to run that fallback browser headed (useful only for local debugging).

## Actor input object example

```json
{
  "query": "artificial intelligence",
  "queries": [],
  "sort": "date",
  "numberOfVideos": 100,
  "uploadDate": "all",
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ],
    "apifyProxyCountry": "US"
  },
  "headless": true
}
```

# 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 = {
    "query": "artificial intelligence",
    "queries": [],
    "proxyConfiguration": {
        "useApifyProxy": true,
        "apifyProxyGroups": [
            "RESIDENTIAL"
        ],
        "apifyProxyCountry": "US"
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("outspoken_strategy/youtube-post-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 = {
    "query": "artificial intelligence",
    "queries": [],
    "proxyConfiguration": {
        "useApifyProxy": True,
        "apifyProxyGroups": ["RESIDENTIAL"],
        "apifyProxyCountry": "US",
    },
}

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

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

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

```

## CLI example

```bash
echo '{
  "query": "artificial intelligence",
  "queries": [],
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ],
    "apifyProxyCountry": "US"
  }
}' |
apify call outspoken_strategy/youtube-post-search-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=outspoken_strategy/youtube-post-search-scraper",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "YouTube Posts (Videos) Search Scraper",
        "description": "Search YouTube videos by keyword. Multiple keywords, sort by upload date/relevance/views/rating, upload-date and date-range filters, auto-pagination. Returns title, description, channel, views, duration and thumbnails. No login needed.",
        "version": "0.0",
        "x-build-id": "NFiHmOyf1dlCwABHA"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/outspoken_strategy~youtube-post-search-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-outspoken_strategy-youtube-post-search-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/outspoken_strategy~youtube-post-search-scraper/runs": {
            "post": {
                "operationId": "runs-sync-outspoken_strategy-youtube-post-search-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/outspoken_strategy~youtube-post-search-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-outspoken_strategy-youtube-post-search-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "properties": {
                    "query": {
                        "title": "Search Query (single keyword)",
                        "type": "string",
                        "description": "One keyword/phrase to search for. Wrap in double quotes for an exact phrase match, e.g. \"econet revenue\". You can also paste several keywords, one per line, to search them all. For a clean list use the \"queries\" field below instead. Leave empty if you use \"queries\"."
                    },
                    "queries": {
                        "title": "Search Queries (multiple keywords)",
                        "type": "array",
                        "description": "Multiple keywords/phrases to search — each is searched separately and results are combined and de-duplicated by video. Takes precedence over/adds to \"query\". numberOfVideos applies PER keyword.",
                        "items": {
                            "type": "string"
                        }
                    },
                    "sort": {
                        "title": "Sort by",
                        "enum": [
                            "date",
                            "relevance",
                            "views",
                            "rating"
                        ],
                        "type": "string",
                        "description": "How YouTube orders the search results: \"date\" (newest first), \"relevance\", \"views\" or \"rating\".",
                        "default": "date"
                    },
                    "numberOfVideos": {
                        "title": "Number of videos",
                        "minimum": 1,
                        "maximum": 1000,
                        "type": "integer",
                        "description": "Maximum number of videos to fetch per keyword. YouTube search stops serving results after roughly 500-600 per query.",
                        "default": 100
                    },
                    "uploadDate": {
                        "title": "Upload date filter",
                        "enum": [
                            "all",
                            "hour",
                            "today",
                            "week",
                            "month",
                            "year"
                        ],
                        "type": "string",
                        "description": "YouTube's own upload-date window for the search (the \"Upload date\" filter dropdown).",
                        "default": "all"
                    },
                    "timeSince": {
                        "title": "Since date",
                        "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
                        "type": "string",
                        "description": "Only return videos published on or after this date (format: yyyy-mm-dd). APPROXIMATE: search results only expose relative publish times (\"3 weeks ago\"), so the comparison uses the derived created_at. Combine with the uploadDate filter for hard cutoffs."
                    },
                    "timeUntil": {
                        "title": "Until date",
                        "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
                        "type": "string",
                        "description": "Only return videos published before this date (format: yyyy-mm-dd). APPROXIMATE — see timeSince."
                    },
                    "proxyConfiguration": {
                        "title": "Proxy configuration",
                        "type": "object",
                        "description": "Proxy to route traffic through. Residential proxies are recommended — YouTube captchas or blocks flagged datacenter IPs.",
                        "default": {
                            "useApifyProxy": true,
                            "apifyProxyGroups": [
                                "RESIDENTIAL"
                            ],
                            "apifyProxyCountry": "US"
                        }
                    },
                    "headless": {
                        "title": "Run browser headless",
                        "type": "boolean",
                        "description": "The actor fetches over plain HTTP and only falls back to a Chrome browser when YouTube blocks it. Uncheck to run that fallback browser headed (useful only for local debugging).",
                        "default": true
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
