# Bilibili Scraper - Videos, Comments, Danmaku & Creators (`kmscrape/bilibili-scraper`) Actor

Scrape Bilibili (B站) videos by keyword, video URL or creator: views, likes, comments, danmaku (弹幕 bullet comments with timestamps), creator followers and the trending board. No login or cookies. 哔哩哔哩 / B站 视频、评论、弹幕与创作者数据。

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

## Pricing

from $2.50 / 1,000 result items

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

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

## Bilibili Scraper — Videos, Comments, Creators & Danmaku

Collect public Bilibili search results, video details, creator profiles and uploads, top-level comments, popular videos, and danmaku (弹幕, bullet comments) through Bilibili's public APIs. No login or user cookies are required.

哔哩哔哩 / B站 视频搜索、评论、弹幕与 UP 主公开数据采集。

### Use cases

- Track public video titles, view counts, and engagement.
- Build creator and upload catalogs.
- Analyze comment sentiment and danmaku reactions, memes, and highlight moments by `timeSec`.
- Create feeds for AI agents / MCP tools, dashboards, and market research.

### Inputs

Provide at least one source: `searchQueries`, `videoUrls`, `creatorUrls`, or `trending: true`.

| Input | Description | Default |
| --- | --- | --- |
| `searchQueries` | Keywords for video search | — (prefilled with `原神`) |
| `videoUrls` | BV/av IDs, video URLs, or b23.tv short links | — |
| `creatorUrls` | Creator profile URLs or numeric mids; collects profile and uploads | — |
| `includeComments` | Fetch top-level comments for videos with an aid | `false` |
| `maxCommentsPerVideo` | Comment cap per video | `20` |
| `includeDanmaku` | Fetch danmaku (弹幕, bullet comments) for every video found or requested | `false` |
| `maxDanmakuPerVideo` | Maximum sorted page 1 danmaku items per video | `1000` (1–5000) |
| `trending` | Include videos from the public popular board | `false` |
| `maxItemsPerSource` | Cap per search, creator upload list, and trending source | `5` |
| `sortBy` | `relevance`, `newest`, or `most played` | `relevance` |
| `fetchFullStats` | Fetch details for search and creator uploads to fill available statistics; adds requests | `false` |
| `proxyConfiguration` | Optional Apify proxy settings | `{ "useApifyProxy": false }` |

Example input:

```json
{
  "videoUrls": ["BV1GJ411x7h7"],
  "includeDanmaku": true,
  "maxDanmakuPerVideo": 50
}
```

The prefilled run searches `原神` and returns up to five video rows. `fetchFullStats` defaults to `false`; set it to `true` to fetch fuller statistics for search and creator uploads. These requests use the shared API pacer.

### Output

Charged row types are `video`, `creator`, `comment`, and `danmaku`. Video rows include IDs, title, description, duration, publish time, creator, engagement stats, tags when available, cover, category, and source. A danmaku row is emitted once per video when enabled. `totalInPool` counts the XML elements returned by Bilibili; `returned` and `items` reflect the sorted, capped results. `sentAt` is an ISO timestamp, and colors are uppercase six-digit RGB hex values.

Example live search row (trimmed):

```json
{
  "type": "video",
  "bvid": "BV1UGa961Ejt",
  "aid": 117357800330860,
  "title": "ピノキオピー - えねみぃ feat. 初音ミク・重音テト",
  "url": "https://www.bilibili.com/video/BV1UGa961Ejt",
  "owner": { "mid": 203655966, "name": "ピノキオピー_official", "url": "https://space.bilibili.com/203655966" },
  "stats": { "views": 2152613, "likes": null, "danmaku": 43302 },
  "category": "VOCALOID·UTAU",
  "source": "search:原神"
}
```

Example real danmaku row (trimmed to three items):

```json
{
  "type": "danmaku",
  "bvid": "BV1GJ411x7h7",
  "cid": 137649199,
  "videoTitle": "Never Gonna Give You Up - Rick Astley",
  "totalInPool": 1200,
  "returned": 3,
  "items": [
    { "timeSec": 0, "text": "《哥斯拉大战金刚秘密片段》", "mode": 5, "fontSize": 25, "color": "#FFFFFF", "sentAt": "2021-02-19T11:32:56.000Z", "senderHash": "8c4702e5", "id": "45399252391690247" },
    { "timeSec": 0.601, "text": "我是一万个点赞，正在反复横跳", "mode": 4, "fontSize": 25, "color": "#E70012", "sentAt": "2020-11-07T09:54:55.000Z", "senderHash": "9e5adeaa", "id": "40685126698926083" },
    { "timeSec": 0.978, "text": "非物质文化遗产", "mode": 5, "fontSize": 25, "color": "#FEF102", "sentAt": "2021-02-08T06:31:20.000Z", "senderHash": "94db4968", "id": "44891481389400069" }
  ]
}
```

Free `summary` and `error` rows report outcomes. Danmaku errors are reported as free rows with source `danmaku:<bvid>`.

### Pricing

Charged at **$2.50 per 1,000 result rows** (`item-result` events). Summary and error rows are free. A run with comments, danmaku, or creator uploads can produce more charged rows than videos alone.

### Limits and FAQ

**How many danmaku do I get?** The public pool endpoint returns the video's current danmaku pool (for example, 1,200 for a 3.5-minute video), not its full history. `maxDanmakuPerVideo` controls how many of those items are returned.

**Which parts of a multi-part video are included?** Only page 1 is fetched.

**Does it need an account, login, or my cookies?** No. It uses anonymous public endpoints and can acquire an anonymous `buvid3` identifier. It never asks for user cookies.

**Why might a video be missing?** Public endpoints can impose rate limits and risk controls (`-412` / `-352`); some videos are region-locked, deleted, private, or unavailable to anonymous visitors. Retries use backoff and refresh the anonymous identifier, but cannot override access restrictions.

**Are all fields always present?** No. Search results may omit full descriptions or tags. Fields unavailable from an endpoint are null or empty; video detail rows provide richer metadata.

**What comments are included?** The first page of top-level replies only. Nested reply threads are not traversed.

**How should I use it in an agent workflow?** Run with search terms, creator IDs, or video URLs, then pass the dataset rows to your agent or MCP pipeline. The `type` field identifies videos, creators, comments, danmaku, errors, and summaries.

# Actor input Schema

## `searchQueries` (type: `array`):

Optional Bilibili video search keywords.

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

Optional BV/av IDs, Bilibili video URLs, or b23.tv short links.

## `creatorUrls` (type: `array`):

Optional space.bilibili.com profile URLs or numeric creator mids. Includes profile and recent uploads.

## `includeComments` (type: `boolean`):

Fetch top-level comments for videos found or requested.

## `maxCommentsPerVideo` (type: `integer`):

Maximum top-level comments per video when comments are enabled.

## `includeDanmaku` (type: `boolean`):

Fetch danmaku (弹幕, bullet comments) for every video found or requested.

## `maxDanmakuPerVideo` (type: `integer`):

Maximum sorted page 1 danmaku items to return for each video when danmaku is enabled.

## `trending` (type: `boolean`):

Include videos from Bilibili's public popular board.

## `maxItemsPerSource` (type: `integer`):

Maximum videos per search, creator uploads, or trending source.

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

Sort search results by relevance, newest, or most played.

## `fetchFullStats` (type: `boolean`):

Fetch detail data for search and creator upload videos to fill engagement statistics; adds paced API requests.

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

Optional Apify proxy configuration applied to all requests.

## Actor input object example

```json
{
  "searchQueries": [
    "原神"
  ],
  "includeComments": false,
  "maxCommentsPerVideo": 20,
  "includeDanmaku": false,
  "maxDanmakuPerVideo": 1000,
  "trending": false,
  "maxItemsPerSource": 5,
  "sortBy": "relevance",
  "fetchFullStats": false,
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}
```

# Actor output Schema

## `results` (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 = {
    "searchQueries": [
        "原神"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("kmscrape/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 = { "searchQueries": ["原神"] }

# Run the Actor and wait for it to finish
run = client.actor("kmscrape/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 '{
  "searchQueries": [
    "原神"
  ]
}' |
apify call kmscrape/bilibili-scraper --silent --output-dataset

```

## MCP server setup

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