# Bilibili 哔哩哔哩 B站 Scraper — Videos, Search & Trends (`china-data-lab/bilibili-data-scraper`) Actor

Scrape Bilibili (bilibili.com), China's largest video platform. Keyword search, video details, trending list and rankings. Returns 17 normalized fields per video: title, description, author, follower-facing engagement stats (views, likes, coins, favorites, shares, danmaku), duration, category, ta...

- **URL**: https://apify.com/china-data-lab/bilibili-data-scraper.md
- **Developed by:** [lijinyu](https://apify.com/china-data-lab) (community)
- **Features:** Limited permissions
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.48 / 1,000 results

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

Learn more: https://docs.apify.com/actors/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

## Bilibili Scraper — Videos, Search, Trends & Comments (China)

Scrape **Bilibili (bilibili.com)**, China's largest video platform with 300M+ monthly users — the Chinese answer to YouTube. Get keyword search results, single video details, the trending feed, category rankings and **video comments** as clean JSON.

No cookies. No login. No proxy. No API key.

### Why Bilibili data

Bilibili is where Chinese Gen-Z discovers products, learns skills and forms opinions. If you research the Chinese market, run influencer campaigns, or build a Chinese-language AI corpus, Bilibili is not optional — it is the primary source.

### What you get

#### Video records

Every video is returned as one flat record with **17 normalized fields**:

| Field | Example |
| --- | --- |
| `bvid` | `BV1rpWjevEip` |
| `aid` | numeric video id (the `av` number) |
| `cid` | numeric chapter id — populated in video, popular and ranking modes; **null in search mode** |
| `title` | video title, highlight tags stripped |
| `description` | full description text |
| `url` | canonical watch URL |
| `cover_url` | https cover image |
| `category` | e.g. `计算机技术` |
| `tags` | comma separated tag list |
| `duration` / `duration_seconds` | `03:17:23` / `11843` |
| `published_at` | ISO 8601, UTC |
| `author.mid` / `author.name` / `author.avatar` | uploader profile |
| `stats.views` | play count |
| `stats.likes` / `stats.coins` / `stats.favorites` / `stats.shares` | engagement |
| `stats.danmaku` | bullet-comment count |
| `stats.comments` | reply count |
| `source` / `keyword` | how this row was found |
| `scraped_at` | ISO 8601, UTC |

#### Comment records (`comments` mode)

Each comment is one flat record; nested replies are flagged, not nested into arrays, so the dataset stays tabular:

| Field | Example |
| --- | --- |
| `comment_id` | `3760801399` (string — Bilibili ids exceed the JS safe integer range) |
| `video_aid` / `video_bvid` / `video_title` / `video_url` | the video the comment belongs to |
| `parent_id` | `0` for a top-level comment, the parent comment id for a nested reply |
| `is_sub_reply` | `true` when the comment is a reply under another comment |
| `text` | comment body, Chinese kept as-is |
| `like_count` / `reply_count` | likes on the comment, replies under it |
| `author.mid` / `author.name` / `author.avatar` / `author.level` | commenter profile |
| `is_vip` | whether the commenter is a Bilibili VIP |
| `published_at` | ISO 8601, UTC |
| `source` | always `comments` |
| `scraped_at` | ISO 8601, UTC |

### Modes

| Mode | What it does | Typical use |
| --- | --- | --- |
| `search` | Keyword search across many keywords and pages | Trend and content research, competitor mapping |
| `video` | Full details for a list of BVIDs | Enriching a known video list |
| `popular` | The current trending feed, paginated | Daily trend monitoring, content ideation |
| `ranking` | Category ranking (`rid`) | Niche leaderboards |
| `comments` | Comments of the given `bvids` — or of the trending videos when no BVID is passed (the default input) | Sentiment, audience language, AI corpora |

### Pricing

Pay per event — you are charged for what the run actually produced:

| Event | Charged for | Price (FREE tier) |
| --- | --- | --- |
| `result` | one video record (`search` / `video` / `popular` / `ranking`) | $0.004 |
| `comment` | one comment record (`comments` mode) | $0.0016 |

Volume tiers discount the same events: SILVER 95%, GOLD 87%, PLATINUM and DIAMOND 80%. A run also incurs the one-time `apify-actor-start` event. Nothing is charged for a record that was not written to the dataset, and the detail data of `comments` mode is charged as comments only — `comments` runs never emit `result` charges.

### Input example

Video search:

```json
{
  "mode": "search",
  "keywords": ["python 教程", "机械键盘"],
  "pages": 2,
  "maxItems": 100
}
```

Comments of two specific videos:

```json
{
  "mode": "comments",
  "bvids": ["BV1GJ411x7h7"],
  "pages": 2,
  "includeReplies": true,
  "sort": "hot",
  "maxItems": 200
}
```

Pinning `bvids` asks Bilibili for one lookup per video. From a cloud/datacenter IP that lookup can be answered with **HTTP 412** — in that case the actor logs the block and falls back to the trending feed instead of failing the run (see Notes). The default `comments` input below never hits that lookup.

Comments of the current trending videos (no BVID needed — the default path):

```json
{
  "mode": "comments",
  "videosLimit": 5,
  "pages": 1,
  "maxItems": 100
}
```

### Output example

Real record from a `search` run:

```json
{
  "source": "search",
  "keyword": "python 教程",
  "bvid": "BV1rpWjevEip",
  "aid": 113006243481679,
  "title": "【全748集】目前B站最全最细的Python零基础全套教程",
  "description": "...",
  "url": "https://www.bilibili.com/video/BV1rpWjevEip",
  "cover_url": "https://i2.hdslb.com/bfs/archive/a979056b1a32012c.jpg",
  "category": "计算机技术",
  "tags": "程序员,Python教程,Python入门零基础",
  "duration": "39:58:14",
  "duration_seconds": 143894,
  "published_at": "2024-08-22T14:59:18+00:00",
  "author": { "mid": 3546597933714079, "name": "Python官方课程", "avatar": "https://i1.hdslb.com/..." },
  "stats": { "views": 22116348, "danmaku": 31200, "likes": 980000, "coins": 210000, "favorites": 640000, "shares": 41000, "comments": 28000 },
  "scraped_at": "2026-11-29T01:20:00+00:00"
}
```

Real records from a `comments` run on `BV1GJ411x7h7` (a top-level comment and one nested reply):

```json
[
  {
    "comment_id": "3760801399",
    "video_aid": "80433022",
    "video_bvid": "BV1GJ411x7h7",
    "video_title": "【官方 MV】Never Gonna Give You Up - Rick Astley",
    "video_url": "https://www.bilibili.com/video/BV1GJ411x7h7",
    "parent_id": "0",
    "is_sub_reply": false,
    "text": "坏消息：被骗了\n好消息：真好听",
    "like_count": 781358,
    "reply_count": 2802,
    "author": {
      "mid": "320773657",
      "name": "老咸鱼A",
      "avatar": "https://i1.hdslb.com/bfs/face/10fbeb658285067378c049b290988ab49c32aee5.jpg",
      "level": 6
    },
    "is_vip": false,
    "published_at": "2020-11-29T12:26:45+00:00",
    "source": "comments",
    "scraped_at": "2026-11-29T04:28:32.921871+00:00"
  },
  {
    "comment_id": "4065967309",
    "video_aid": "80433022",
    "video_bvid": "BV1GJ411x7h7",
    "video_title": "【官方 MV】Never Gonna Give You Up - Rick Astley",
    "video_url": "https://www.bilibili.com/video/BV1GJ411x7h7",
    "parent_id": "3760801399",
    "is_sub_reply": true,
    "text": "坏消息:好消息\n好消息:坏消息",
    "like_count": 43209,
    "reply_count": 0,
    "author": {
      "mid": "495970426",
      "name": "-Megumin_",
      "avatar": "https://i1.hdslb.com/bfs/face/57f64faa9a0c50bba4e88c38b04200e0fde543e2.jpg",
      "level": 6
    },
    "is_vip": false,
    "published_at": "2021-02-05T17:40:23+00:00",
    "source": "comments",
    "scraped_at": "2026-11-29T04:28:32.921871+00:00"
  }
]
```

### Notes and limits

- Data is read from Bilibili's public web endpoints. Only publicly visible videos and comments are returned.
- Very large `pages` values may hit platform rate limits; the actor retries with backoff.
- Duration for multi-part collections reports the collection total, as Bilibili does.
- `cid` is **null in `search` mode only**: the search endpoint does not return the chapter id. `video`, `popular` and `ranking` all populate it (verified on real runs: popular 20/20, ranking 20/20, search 0/15).
- **`comments` mode uses the cursor endpoint** `/x/v2/reply/main` (20 comments per page, hot or newest order). Comments are de-duplicated by `comment_id` across pages and across videos, and the old `/x/v2/reply` endpoint is only a fallback — in anonymous runs it returns ~3 records.
- `includeReplies: false` skips the replies nested under top-level comments; `parent_id` tells you which comment a reply belongs to.
- `comments` mode **without `bvids` reads the current trending feed** — this is the default input (the schema defaults `bvids` to `[]`) and it is the reliable path from a cloud IP, because it only calls `/x/web-interface/popular`, which is not rate-limited the way the per-video lookup is. Its output changes hour to hour, so pin `bvids` if you need a reproducible dataset.
- **`bvids` in `comments` mode may hit Bilibili's risk control (HTTP 412) on datacenter IPs.** Bilibili throttles the `/x/web-interface/view` lookup per IP; the same request from a home connection returns 200 while a cloud runner gets 412 on every attempt. The actor retries with backoff, and when the block persists it does not fail the run: it logs `[comments] view API blocked (HTTP 412), falling back to popular feed` and reads comments from the trending feed instead, so the run still returns data (charged per comment, exactly like the normal path).
- What the fallback means for your dataset: the returned rows come from the trending videos, so `video_bvid` will **not** be the BVIDs you passed in — check the `[comments] view API blocked (HTTP 412)` line in the run log to tell the two paths apart. If you need comments of specific videos from a cloud IP, run the actor behind a residential/backbone proxy or run it locally: the API host is overridable with the `BILI_API_BASE` environment variable (e.g. `BILI_API_BASE=https://your-proxy.example.com`), which is the supported way to route around the block.
- Export results as JSON, CSV or Excel from the dataset tab, or pull them with the Apify API.

#### Rate limiting and fallback

`video` mode resolves each BVID through three layers: the public `view` API,
then the signed `wbi/view` API, then a `search/type` lookup. On a cloud IP,
Bilibili frequently answers `view` with HTTP 412 — the actor logs
`[video] view API blocked for BVxxx, trying fallback` and moves to the next layer.

If all three fail for a given BVID it is skipped, not fatal:
`[video] skipped N bvids due to rate limiting`. The run still succeeds and returns
whatever resolved. For guaranteed coverage of specific videos, run locally or
through your own proxy.

# Actor input Schema

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

search = keyword search, video = details for given BVIDs, popular = the trending feed, ranking = category ranking, comments = comments of given BVIDs, or of the top trending videos when no BVID is filled in (that is the default and the path that works from cloud IPs).

## `keywords` (type: `array`):

Search terms (search mode only). Chinese or English both work.

## `pages` (type: `integer`):

search mode: result pages per keyword (20 videos per page). comments mode: comment pages per video (20 comments per page).

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

Video IDs such as BV1GJ411x7h7. Used by video mode (details) and comments mode (comments of these videos). Leave it empty in comments mode to read the current trending feed - that is the default input and the reliable path from a cloud/datacenter IP, where Bilibili may answer the per-video lookup with HTTP 412 and the actor then falls back to the trending feed automatically.

## `videosLimit` (type: `integer`):

comments mode only: how many trending videos to read comments from. Drives the default path (no BVID given) and the automatic fallback when a BVID lookup is blocked by Bilibili (HTTP 412).

## `includeReplies` (type: `boolean`):

comments mode only: also return the replies under each top-level comment.

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

comments mode only: hot = by popularity, time = newest first.

## `rid` (type: `integer`):

0 = all categories. Examples: 1 animation, 4 gaming, 36 knowledge, 188 tech.

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

Hard cap on returned records - videos in search/video/popular/ranking, comments in comments mode. Keep it low while testing, you pay per record returned.

## Actor input object example

```json
{
  "mode": "search",
  "keywords": [
    "python"
  ],
  "pages": 1,
  "bvids": [],
  "videosLimit": 3,
  "includeReplies": true,
  "sort": "hot",
  "rid": 0,
  "maxItems": 10
}
```

# Actor output Schema

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

No description

# 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 = {
    "keywords": [
        "python"
    ],
    "videosLimit": 3,
    "maxItems": 10
};

// Run the Actor and wait for it to finish
const run = await client.actor("china-data-lab/bilibili-data-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 = {
    "keywords": ["python"],
    "videosLimit": 3,
    "maxItems": 10,
}

# Run the Actor and wait for it to finish
run = client.actor("china-data-lab/bilibili-data-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 '{
  "keywords": [
    "python"
  ],
  "videosLimit": 3,
  "maxItems": 10
}' |
apify call china-data-lab/bilibili-data-scraper --silent --output-dataset

```

## MCP server setup

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