# Bilibili Scraper: Videos, Comments & Danmaku (B站 哔哩哔哩) (`dheerajitbhu/bilibili-scraper`) Actor

Scrape Bilibili (哔哩哔哩, B站) without login: keyword search, video details, comments and replies, popular videos, creator profiles and danmaku (弹幕) summaries. $2 per 1,000 rows, datacenter proxy by default.

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

## Pricing

from $2.00 / 1,000 row scrapeds

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 & Danmaku (B站 哔哩哔哩)

Scrape public data from **Bilibili (哔哩哔哩, B站)**, China's largest video community, with **no login, no cookie and no API key**. Search videos by keyword, get full video details, export **comments and replies**, pull the **popular / trending** board and **creator profiles**, and summarise a video's **danmaku (弹幕)** bullet comments into one row.

**$2 per 1,000 rows.** It runs on Apify's datacenter proxy by default and switches to residential automatically only if Bilibili blocks the run.

> 中文简介：B站数据采集，无需登录、无需 Cookie。支持关键词搜索视频、视频详情（播放、点赞、投币、收藏、分享、弹幕数）、评论与楼中楼回复、热门视频、UP主资料（粉丝数、投稿数、获赞数）和弹幕分析（弹幕密度、高峰分钟、弹幕样本）。按条计费，每 1000 条 2 美元。

### What you can scrape

| Mode | What you get | Input |
|---|---|---|
| `search` | Videos matching keywords (sort, length and date filters) | `searchQueries` |
| `video_detail` | Full stats: views, likes, coins, favorites, shares, danmaku, comments, parts, `hasSubtitles` | `videoUrls` (links or BV ids) |
| `video_comments` | Top-level comments (popular or newest first) plus optional replies | `videoUrls` |
| `popular` | Bilibili's popular / trending board | (none) |
| `user_profile` | Creator (UP主) followers, following, video count, total likes, level, verification, bio | `userIds` (mid or space.bilibili.com link) |

Add-ons for `search`, `video_detail` and `popular`: `includeComments`, `includeReplies`, `includeDanmaku`, `includeVideoDetails`.

### Pricing (pay per event)

| Event | Price |
|---|---|
| Run start | $0.001 per run |
| Row (video, comment, reply or creator) | **$0.002** ($2 per 1,000) |
| Danmaku summary (one row per video, only with `includeDanmaku`) | $0.01 |

Error rows are free. Set `maxChargeUsd` (default $5) and the run stops cleanly before it goes over; rows already delivered are kept.

Example costs: 100 search results = $0.20. 10 videos × 50 comments = 510 rows ≈ $1.02. Danmaku summaries for 50 videos = $0.50.

### Input examples

Search, newest first, with comments:

```json
{
  "mode": "search",
  "searchQueries": ["机械键盘", "原神"],
  "maxResults": 50,
  "sortOrder": "pubdate",
  "publishedAfter": "2026-10-01",
  "includeComments": true,
  "maxComments": 20
}
```

Comments and replies of specific videos:

```json
{
  "mode": "video_comments",
  "videoUrls": ["https://www.bilibili.com/video/BV1xx411c7mD"],
  "maxComments": 200,
  "sortComments": "hot",
  "includeReplies": true,
  "maxRepliesPerComment": 10
}
```

Video details with a danmaku summary:

```json
{ "mode": "video_detail", "videoUrls": ["BV1xx411c7mD"], "includeDanmaku": true }
```

Creator profiles (schedule it daily to track follower growth):

```json
{ "mode": "user_profile", "userIds": ["452412746", "https://space.bilibili.com/265504053"] }
```

### Output examples

Video:

```json
{
  "type": "video", "source": "detail", "bvid": "BV1frJB64EQv", "aid": 117456668459441, "cid": 42824894014,
  "title": "2026年双十一高性价比机械键盘选购推荐", "url": "https://www.bilibili.com/video/BV1frJB64EQv",
  "thumbnailUrl": "https://i1.hdslb.com/bfs/archive/....jpg", "duration": 2295, "parts": 1,
  "viewCount": 2179, "likeCount": 106, "coinCount": 8, "favoriteCount": 151, "shareCount": 12,
  "danmakuCount": 98, "replyCount": 41, "authorName": "UP主名", "authorMid": 12345678,
  "category": "数码", "tags": ["机械键盘"], "publishDate": "2026-10-16T10:00:00+00:00",
  "hasSubtitles": true, "scrapedAt": "2026-10-18T15:48:14+00:00"
}
```

Comment or reply:

```json
{
  "type": "reply", "videoBvid": "BV1frJB64EQv", "commentId": 321073847136, "rootCommentId": 321056652768,
  "text": "售后换呗", "likeCount": 1, "replyCount": 0, "createdAt": "2026-10-18T02:47:21+00:00",
  "authorName": "景行推荐", "authorMid": 2133808831, "scrapedAt": "2026-10-18T15:48:14+00:00"
}
```

Danmaku summary (real row from a test run on 2026-10-18):

```json
{
  "type": "danmaku", "videoBvid": "BV1qm41197pQ", "danmakuFetched": 1101, "danmakuTotal": 1303,
  "danmakuPoolCapped": true, "danmakuUniqueSenders": 875, "danmakuPerMinute": 87.96,
  "danmakuPeakMinute": 4, "danmakuPeakMinuteCount": 183, "danmakuFirstAt": 4.8, "danmakuLastAt": 748.3,
  "danmakuSample": [{"atSecond": 4.8, "text": "不是还有个茶轴吗？"}, {"atSecond": 36.8, "text": "惊人收藏"}]
}
```

Creator (real row, 2026-10-18):

```json
{
  "type": "user", "mid": 452412746, "name": "Yooupi食途", "profileUrl": "https://space.bilibili.com/452412746",
  "bio": "一个上山打虎，下海捉蛟的清奇频道。…", "level": 6, "followers": 2323150, "following": 126,
  "videoCount": 278, "totalLikes": 15814347, "isVerified": true, "verificationTitle": "2023百大UP主、知名UP主"
}
```

### Compact output for AI agents

Set **Output format** to `compact` and the run still pushes the same rows to the dataset
at the same price — nothing about billing changes. It additionally writes `OUTPUT_COMPACT`
to the run's key-value store: a lossless columnar JSON encoding of the same rows (one
column-name header plus one array per row, instead of repeating every key name on every
row), which is cheaper to hand to an LLM than the plain dataset JSON.

Measured on a real 406-row export of this actor's comment/reply rows (see
`benchmarks/compact-output/` in this repo for methodology and all 5 actors' numbers):

| Tokenizer | Pretty JSON | Minified JSON | Compact | vs Pretty | vs Minified |
|---|---:|---:|---:|---:|---:|
| cl100k_base (GPT-4/3.5) | 74,310 | 59,673 | 45,538 | 38.7% smaller | 23.7% smaller |
| o200k_base (GPT-4o) | 67,672 | 53,034 | 39,320 | 41.9% smaller | 25.9% smaller |

Decoding it back to the normal row objects is five lines of Python:

```python
def decode_columnar(payload):
    cols, marker = payload["columns"], payload["missing"]
    return [{c: v for c, v in zip(cols, row) if v != marker}
            for row in payload["rows"]]
```

### Good to know

- **Public data only.** The actor never logs in. Comment rows carry only the public nickname and mid; no avatars or other personal fields.
- **Subtitles:** Bilibili only serves subtitle and AI-subtitle text to logged-in users, so this actor reports `hasSubtitles` (whether tracks exist) and does not download the text.
- **Creator upload lists** (space pages) are blocked by Bilibili's risk control without login. To find a creator's videos, use `search` with their name.
- **Search depth:** Bilibili caps one keyword at about 1,000 results. Use date windows or more specific keywords to go further.
- **Danmaku:** Bilibili keeps a capped pool per video. `danmakuPoolCapped` tells you when the summary covers part of the total.
- **Reliability:** a self-test runs every day against live Bilibili endpoints, so breakages get spotted and fixed fast. If Bilibili blocks every request in a run, the run is marked **failed** instead of ending green with 0 rows, so your schedule alerts fire.

### FAQ

**Is there an official Bilibili API?** Not for international developers. This actor uses the same public endpoints the website uses.

**English or Chinese keywords?** Bilibili indexes Chinese text. Searching 耐克 returns many more videos than "Nike".

**How do I schedule it?** Save your input as a Task in Apify Console, then add a Schedule (for example `0 8 * * *` for daily at 8 AM).

**关键词：** B站爬虫, 哔哩哔哩采集, B站评论采集, 弹幕分析, B站热门, UP主数据, Bilibili API, Bilibili comments scraper, danmaku scraper.

# Actor input Schema

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

What to scrape. No login or cookie is needed in any mode.

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

Used in 'search' mode. Chinese keywords return far more results than English ones (耐克 vs Nike). If left empty in search mode, the run uses 原神 as a sample keyword.

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

Used in 'video_detail' and 'video_comments'. Example: https://www.bilibili.com/video/BV1xx411c7mD or BV1xx411c7mD

## `userIds` (type: `array`):

Used in 'user_profile'. The number in space.bilibili.com/{mid}; pasting the link works too.

## `maxResults` (type: `integer`):

Bilibili caps one keyword at about 1,000 results.

## `sortOrder` (type: `string`):

Used in 'search' mode.

## `durationFilter` (type: `string`):

Used in 'search' mode.

## `publishedAfter` (type: `string`):

Optional, search mode. 2026-04-15, 20260415 or ISO 8601 (no zone = UTC). An unreadable value is not applied and the run status says so.

## `publishedBefore` (type: `string`):

Optional, search mode. Same formats as 'Published after'.

## `includeVideoDetails` (type: `boolean`):

Adds coins, shares, part count and the hasSubtitles flag to each search/popular row (one extra request per video, no extra charge).

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

In search, video_detail and popular modes: also return each video's comments as rows (type 'comment'). Each comment is a billed row.

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

Used in 'video_comments' and when 'Also scrape comments' is on.

## `sortComments` (type: `string`):

Used for comments in every mode.

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

Adds reply rows (type 'reply', with rootCommentId). Each reply is a billed row.

## `maxRepliesPerComment` (type: `integer`):

Used when 'Include replies to comments' is on.

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

One extra row per video: danmaku count fetched, unique senders, per-minute rate, peak minute and a timeline sample. Billed as one 'danmaku-summary' event ($0.01), not per danmaku.

## `danmakuSampleSize` (type: `integer`):

Danmaku texts spread across the timeline, inside the single summary row.

## `outputFormat` (type: `string`):

Dataset rows are always pushed and charged the same either way. 'compact' additionally writes OUTPUT_COMPACT to the run's key-value store: a lossless columnar JSON encoding of the same rows that is far cheaper to feed to an LLM and decodes back to the exact same rows.

## `maxChargeUsd` (type: `number`):

Hard spending cap. The run stops cleanly before going over it; rows already delivered are kept.

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

Default: Apify datacenter proxy. If Bilibili's risk control blocks it (HTTP 412 / -352), the run switches once to the RESIDENTIAL group automatically. Pick RESIDENTIAL to use it from the start.

## `requestIntervalSecs` (type: `number`):

Polite pacing. Faster pacing triggers Bilibili's HTTP 412 risk control.

## Actor input object example

```json
{
  "mode": "search",
  "searchQueries": [
    "原神"
  ],
  "maxResults": 20,
  "sortOrder": "totalrank",
  "durationFilter": "any",
  "includeVideoDetails": false,
  "includeComments": false,
  "maxComments": 20,
  "sortComments": "hot",
  "includeReplies": false,
  "maxRepliesPerComment": 10,
  "includeDanmaku": false,
  "danmakuSampleSize": 25,
  "outputFormat": "standard",
  "maxChargeUsd": 5,
  "proxyConfiguration": {
    "useApifyProxy": true
  },
  "requestIntervalSecs": 1
}
```

# Actor output Schema

## `results` (type: `string`):

Videos, comments, replies, creators and danmaku summaries (field 'type').

# 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": [
        "原神"
    ],
    "proxyConfiguration": {
        "useApifyProxy": true
    }
};

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

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

```

## MCP server setup

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