# Bilibili Scraper: Videos, Danmaku & Comments (B站) (`xiaoliang527/bilibili-video-danmaku`) Actor

Search Bilibili (B站) videos by keyword or fetch by URL: titles, stats, tags, uploader, danmaku bullet comments and hot comment threads. No login or cookies. From $2 per 1,000 videos.

- **URL**: https://apify.com/xiaoliang527/bilibili-video-danmaku.md
- **Developed by:** [xiao liang](https://apify.com/xiaoliang527) (community)
- **Categories:** Social media, Videos
- **Security:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.00 / 1,000 videos

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, Danmaku & Comments (B站)

Search **Bilibili (哔哩哔哩, B站)** videos by keyword or fetch them by URL and get clean JSON: title, description, tags, uploader, publish time, duration and full stats (views, likes, coins, favorites, shares, danmaku and comment counts). Optionally add the **danmaku (弹幕) bullet comments** with their position in the video, and the hot comment threads.

- **No login, no cookies.** Only public data. Your account is never involved.
- **Cheap.** $2 per 1,000 videos, danmaku $3 per 1,000 videos (all danmaku of a video for one price).
- **Fast.** Runs without proxies by default; results start in seconds.

### Input

| Field | Description |
|---|---|
| `searchKeywords` | Keywords to search, Chinese or English, e.g. `["机器学习", "EV review"]` |
| `videoUrls` | Video URLs, `BV1...` ids or `av...` ids |
| `maxResultsPerKeyword` | Results per keyword (default 20, up to 1,000) |
| `sort` | `totalrank` (relevance), `click` (views), `pubdate` (newest), `dm` (most danmaku), `stow` (most favorited) |
| `includeDanmaku`, `maxDanmaku` | Add danmaku for each video |
| `maxComments`, `includeReplies` | Add hot comment threads (see limits) |

```json
{
  "searchKeywords": ["机器学习"],
  "maxResultsPerKeyword": 50,
  "sort": "click",
  "includeDanmaku": true
}
```

### Output

Every dataset item has a `type`: `video`, `danmaku`, `comment` or `error`.

```json
{
  "type": "video",
  "bvid": "BV1owrpYKEtP",
  "url": "https://www.bilibili.com/video/BV1owrpYKEtP",
  "title": "【官方中英】2025年公认最好的【吴恩达机器学习课程】...",
  "author": {"mid": 3493134768016008, "name": "吴恩达AI_AndrewNg"},
  "published_at": "2025-01-04T08:38:47+00:00",
  "duration_sec": 83096,
  "tags": ["pytorch", "人工智能", "机器学习"],
  "category": "计算机技术",
  "stats": {"views": 4601796, "likes": 34463, "favorites": 93668, "danmaku": 8104, "comments": 2498}
}
```

```json
{"type": "danmaku", "bvid": "BV1owrpYKEtP", "text": "跟不上，根本跟不上", "video_time_sec": 295.68, "color": "#ffffff", "sent_at": "2025-10-11T14:20:54+00:00"}
```

Videos fetched by URL also include `coins`, `shares`, `cid` and the list of `pages` (parts).

### Use cases

- **Market and brand research in China**: what is being said about a product, brand or topic on Bilibili, with view and engagement numbers.
- **Danmaku analysis**: viewer reactions at the exact second they happen, for sentiment analysis, highlight detection or LLM summaries.
- **Creator and content discovery**: find the most viewed or newest videos for a keyword.

### Use it from code, n8n or an AI agent

```python
from apify_client import ApifyClient

client = ApifyClient("<YOUR_APIFY_TOKEN>")
run = client.actor("xiaoliang527/bilibili-video-danmaku").call(
    run_input={"searchKeywords": ["机器学习"], "maxResultsPerKeyword": 20, "includeDanmaku": True})
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    if item["type"] == "video":
        print(item["title"], item["stats"]["views"])
```

**MCP (Claude, Cursor):** `https://mcp.apify.com?tools=xiaoliang527/bilibili-video-danmaku` with your Apify token as Bearer header.

### Pricing

| Event | Price |
|---|---|
| Video | $0.002 ($2 / 1,000) |
| Danmaku for one video (up to `maxDanmaku`) | $0.003 |
| Comment | $0.0005 |

Errors (invalid URL, deleted video) are reported with `type: "error"` and not charged. Set a maximum cost per run in the run options and the Actor stops cleanly when it is reached.

### Limits

- Without login Bilibili only shows the **top hot comment threads** of a video (about 3 root comments plus their replies). Full comment sections are not available.
- The danmaku endpoint returns the most recent part of the danmaku pool (usually up to a few thousand per video), not the full history.
- Search returns at most 1,000 results (50 pages) per keyword, like the Bilibili website.
- Only public data is collected. No private, members-only or deleted content.

# Actor input Schema

## `searchKeywords` (type: `array`):

Search Bilibili videos for each keyword (Chinese or English).

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

Bilibili video URLs, BV ids (BV1xx...) or av ids.

## `maxResultsPerKeyword` (type: `integer`):

How many search results to return for each keyword (20 per page, up to 50 pages).

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

Order of search results.

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

Fetch the danmaku pool of each video: text, time in video, colour, send time.

## `maxDanmaku` (type: `integer`):

Bilibili serves the most recent part of the danmaku pool, usually up to a few thousand.

## `maxComments` (type: `integer`):

0 = no comments. Without login Bilibili only exposes the top hot comment threads (about 3 root comments plus their replies).

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

Also fetch replies under each root comment (counted toward max comments).

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

Usually not needed. Turn on if you see rate-limit errors.

## Actor input object example

```json
{
  "searchKeywords": [
    "机器学习"
  ],
  "maxResultsPerKeyword": 20,
  "sort": "totalrank",
  "includeDanmaku": false,
  "maxDanmaku": 1000,
  "maxComments": 0,
  "includeReplies": true,
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}
```

# Actor output Schema

## `items` (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 = {
    "searchKeywords": [
        "机器学习"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("xiaoliang527/bilibili-video-danmaku").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 = { "searchKeywords": ["机器学习"] }

# Run the Actor and wait for it to finish
run = client.actor("xiaoliang527/bilibili-video-danmaku").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 '{
  "searchKeywords": [
    "机器学习"
  ]
}' |
apify call xiaoliang527/bilibili-video-danmaku --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,xiaoliang527/bilibili-video-danmaku"
        }
    }
}
```

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/Pcu05yTXMuiPHIsmD/builds/YYn8pibPo9gmPEdAE/openapi.json
