# Bilibili Video Scraper (`crawlerbros/bilibili-scraper`) Actor

Scrape Bilibili (bilibili.com) - China's largest video platform. Search videos (title, author, view counts, duration, cover), fetch single video details by bvid/aid/URL, popular feed, and partition rankings - all through public api.bilibili.com endpoints, no login required.

- **URL**: https://apify.com/crawlerbros/bilibili-scraper.md
- **Developed by:** [Crawler Bros](https://apify.com/crawlerbros) (community)
- **Categories:** Automation, Social media, Videos
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.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.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — 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

## Bilibili Video Scraper

Scrape [Bilibili](https://www.bilibili.com/) — China's largest video platform — via its public `api.bilibili.com` endpoints (no login). Search videos by keyword, fetch single video details by **bvid / aid / URL**, get the **popular feed**, or **partition rankings**. Output includes title, author, view counts, duration, cover image, publish time and tags.

### What this actor does

- **Four modes:** `search` (default), `byVideoUrl`, `popular`, `ranking`
- **Search ordering** (`order`): total rank / most viewed / newest / most danmaku / rating score
- **15 ranking partitions** as a dropdown (rid): all, anime, music, game, entertainment, knowledge, guichu, dance, fashion, life, movie, digital, food, animal, car — every option verified against the live ranking API
- **Search partition filter** (`tids`) and **search duration filter** (`duration`: <10 / 10-30 / 30-60 / >60 min), both verified against the live search API
- **buvid bootstrap:** visits bilibili.com once to obtain the `buvid3` cookie the search API requires
- **Web-search HTML fallback** (search.bilibili.com SSR cards, with full title/author/views/duration/cover parsing) if the search API rate-limits
- **Filters:** min view count, title/description/author keyword
- **Auto-escalation:** lazy-engages Apify AUTO datacenter proxy on 403/429/5xx; retries with backoff (bilibili is latency-flaky)
- **Empty fields are omitted**; every record carries `sourceUrl`, `scrapedAt`, `recordType`

### Output per video

- `bvid`, `aid`
- `title` (HTML `<em>` keywords stripped), `description`
- `author`, `authorMid`
- `viewCount`, `danmaku`, `replyCount`, `favorites`, `likeCount`, `coinCount`, `shareCount`
- `duration` (seconds), `durationText` (`3:17:23`)
- `coverUrl` (hdslb CDN, https-normalized), `publishTime` (UTC ISO)
- `typeName` (partition label), `uploadRegion` (upload location, when published), `pageCount` (multi-part videos), `resolution` (`1920x1080`)
- `tags[]` (search mode)
- `publishDate` (YYYY-MM-DD, HTML-fallback records only; relative SSR labels like "5小时前" are dropped — only real dates are emitted)
- `videoUrl`, `recordType: "video" | "error"`, `scrapedAt`

### Input

| Field | Type | Default | Description |
|---|---|---|---|
| `mode` | select | `search` | `search` / `byVideoUrl` / `popular` / `ranking` |
| `searchQuery` | string | `python` | Keyword (mode=search) |
| `videoUrls` | array | – | Video URLs (mode=byVideoUrl) |
| `bvids` | array | – | BV IDs (mode=byVideoUrl) |
| `aids` | array | – | Numeric video IDs (mode=byVideoUrl) |
| `rid` | select | `0` | Ranking partition (15 options) |
| `order` | select | `totalrank` | Search sort |
| `tids` | select | `0` | Search partition filter |
| `duration` | select | `0` | Search duration range |
| `minViewCount` | int | – | View-count floor |
| `containsKeyword` | string | – | Title/description/author substring filter |
| `maxItems` | int | `20` | Hard cap (1–500) |

#### Example: most-viewed Python tutorials

```json
{
  "mode": "search",
  "searchQuery": "python",
  "order": "click",
  "minViewCount": 100000,
  "maxItems": 15
}
```

#### Example: 30-60 minute food videos from the food partition

```json
{
  "mode": "search",
  "searchQuery": "美食",
  "tids": "211",
  "duration": "3",
  "maxItems": 10
}
```

#### Example: single video

```json
{
  "mode": "byVideoUrl",
  "videoUrls": ["https://www.bilibili.com/video/BV1wD4y1o7AS/"]
}
```

#### Example: music ranking

```json
{
  "mode": "ranking",
  "rid": "3",
  "maxItems": 20
}
```

### Cover images

Cover URLs point at `i*.hdslb.com` — verified `HTTP 200 image/jpeg` from a clean shell (no Referer/cookies); protocol-relative and `http://` URLs are normalized to `https://`.

### Anti-bot notes

- `api.bilibili.com` search endpoints require a `buvid3` cookie — the actor bootstraps it by visiting bilibili.com first.
- The platform rate-limits aggressively (`-799`/`-1200` codes, intermittent timeouts) — retries with backoff are built in; web-search HTML is the fallback.

### Data source

Public api.bilibili.com endpoints: `x/web-interface/search/type`, `x/web-interface/view`, `x/web-interface/popular`, `x/web-interface/ranking/v2`. No login required.

### Limitations

- User-space video lists (`x/space/wbi/arc/search`) require WBI request signing — not supported in v1.
- The `资讯` (news) and `运动` (sports) partitions and the invalid tid `153` were removed from the rid/tids dropdowns because the ranking/search APIs reject them (`-400`).
- Search-mode `tids` and `duration` filters apply to the API path; if the search API rate-limits or times out mid-run (common — the platform is latency-flaky), the HTML fallback returns unfiltered results, so the filter may not hold on every run. Retrying the run usually returns the filtered set.
- Garbage search queries: the platform returns real recommended videos instead of an empty result set, so an "impossible" query still yields real records (platform behavior, not a filter leak).
- Invalid bvids/URLs produce typed `recordType: "error"` records (no silent drops).

# Actor input Schema

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

What to fetch.

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

Keyword, e.g. `python` or `美食`.

## `videoUrls` (type: `array`):

Bilibili video URLs, e.g. https://www.bilibili.com/video/BV1xx411c7mD/

## `bvids` (type: `array`):

Bilibili BV IDs, e.g. BV1xx411c7mD

## `aids` (type: `array`):

Bilibili numeric video IDs (aid), e.g. 170001

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

Bilibili partition id (mode=ranking).

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

Search result ordering (mode=search).

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

Narrow search results to one Bilibili partition, same ids as ranking (mode=search).

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

Keep only videos within this length range (mode=search).

## `minViewCount` (type: `integer`):

Drop videos with fewer views.

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

Only keep videos whose title, description or author contains this substring (case-insensitive).

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

Hard cap on emitted records.

## Actor input object example

```json
{
  "mode": "search",
  "searchQuery": "python",
  "videoUrls": [],
  "bvids": [],
  "aids": [],
  "rid": "0",
  "order": "totalrank",
  "tids": "0",
  "duration": "0",
  "maxItems": 20
}
```

# Actor output Schema

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

Dataset containing all scraped Bilibili videos.

# 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 = {
    "mode": "search",
    "searchQuery": "python",
    "videoUrls": [],
    "bvids": [],
    "aids": [],
    "rid": "0",
    "order": "totalrank",
    "tids": "0",
    "duration": "0",
    "maxItems": 20
};

// Run the Actor and wait for it to finish
const run = await client.actor("crawlerbros/bilibili-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 = {
    "mode": "search",
    "searchQuery": "python",
    "videoUrls": [],
    "bvids": [],
    "aids": [],
    "rid": "0",
    "order": "totalrank",
    "tids": "0",
    "duration": "0",
    "maxItems": 20,
}

# Run the Actor and wait for it to finish
run = client.actor("crawlerbros/bilibili-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 '{
  "mode": "search",
  "searchQuery": "python",
  "videoUrls": [],
  "bvids": [],
  "aids": [],
  "rid": "0",
  "order": "totalrank",
  "tids": "0",
  "duration": "0",
  "maxItems": 20
}' |
apify call crawlerbros/bilibili-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,crawlerbros/bilibili-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/RBeL478OTU7eZydOU/builds/fmiT9YCmUpBUIOmJD/openapi.json
