# Bilibili Video Scraper —Videos, Comments, & Danmaku (`datapilot/bilibili-video-scraper-videos-comments-danmaku`) Actor

Scrape Bilibili video details, including title, description, creator information, engagement statistics, danmaku bullet comments, and top video comments. Export all collected data to an Apify Dataset in JSON format.

- **URL**: https://apify.com/datapilot/bilibili-video-scraper-videos-comments-danmaku.md
- **Developed by:** [Data Pilot](https://apify.com/datapilot) (community)
- **Security:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $5.00 / 1,000 scraped results

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

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 Video Scraper — Videos, Comments & Danmaku** is a powerful Apify Actor designed to extract video details, top comments, and live bullet comments (danmaku) from any public Bilibili video. This tool provides comprehensive **Bilibili Video Scraper** intelligence including title, description, creator, views, likes, coins, favorites, shares, comments, and danmaku text with timestamps. Whether you're analyzing audience reactions, researching content trends, or collecting data for social listening, the Bilibili Video Scraper delivers structured insights efficiently.

With simple BV ID or video URL input, visitor-cookie setup, danmaku XML parsing, comment extraction, and reliable Apify Dataset delivery, this **Bilibili Video Scraper** actor turns one video into a clean dataset of metadata, comments, and bullet comments. It focuses on key engagement signals including views, likes, coins, and audience reactions, making **Bilibili Video Scraper** an essential tool for video analytics and audience research.

***

### 📋 Table of Contents

- [Features](#-features)
- [Data Source](#-data-source)
- [How It Works](#-how-it-works)
- [Input](#-input)
- [Output](#-output)
- [Technical Stack](#-technical-stack)
- [Data Fields](#-data-fields-explained)
- [Use Cases](#-use-cases)
- [Quick Start](#-quick-start)
- [Configuration](#-configuration)
- [Performance](#-performance)
- [Important Notes](#-important-notes)
- [License & Legal](#-license--legal)

***

### 🔥 Features

- **Video Metadata Extraction** – Collects title, description, creator, publish date, duration, cover image, and engagement stats. This is the core of **Bilibili Video Scraper**.
- **Danmaku (Bullet Comment) Extraction** – Parses the video's danmaku XML to capture comment text, timestamp in the video, and font color.
- **Top Comment Extraction** – Collects top comments with author, likes, reply count, and publish date.
- **URL or BV ID Input** – Accepts a full Bilibili video URL or a plain BV ID and extracts the BV ID automatically.
- **Engagement Stats** – Captures views, likes, coins, favorites, shares, and danmaku count for each video.
- **Visitor Cookie Setup** – Creates visitor cookies before requests to reduce Bilibili's anti-bot blocking (error -412).
- **Clean Text Output** – Strips HTML tags and decodes HTML entities from titles, descriptions, and comments.
- **Configurable Item Limit** – Control how many danmaku and comments to collect with `maxComments`.
- **Apify Proxy Support** – Optional Apify Proxy for reliable **Bilibili Video Scraper** access.
- **Proxy Fallback Handling** – Automatically retries without a proxy if a proxied request fails with an error.
- **Single-Batch Dataset Push** – Pushes all records to the Apify Dataset together once collection completes.
- **Detailed Logging** – Logs proxy status, scraping progress, and completion for every **Bilibili Video Scraper** run.

***

### 📊 Data Source

#### **Bilibili Public Endpoints**

- **Video details**: `https://api.bilibili.com/x/web-interface/view`
- **Danmaku (bullet comments)**: `https://comment.bilibili.com/{cid}.xml`
- **Comments**: `https://api.bilibili.com/x/v2/reply`
- **Access Method**: Browser-impersonated HTTP requests via `curl_cffi` (Chrome 124 fingerprint) with visitor cookies, parsing JSON and XML responses
- **Coverage**: Public Bilibili videos
- **Data**: Video metadata, engagement statistics, danmaku, and top-level comments
- **Access**: Public endpoints, no login or API key required
- **Update Frequency**: Reflects live data at time of run

***

### ⚙️ How It Works

The Bilibili Video Scraper accepts one video URL or BV ID. It sets up visitor cookies, fetches the video details, then uses the video's `cid` to download danmaku and its `aid` to download top comments. Everything is combined into one list of records and pushed to the Apify Dataset as a single batch.

**Key Processing Steps:**

1. **Input Parsing** – Read `videoUrlOrBvid` and `maxComments`
2. **BV ID Extraction** – Pull the `BV...` ID out of a URL, or use the value as given
3. **Proxy Setup** – Configure Apify Proxy if enabled, with automatic direct-connection fallback
4. **Cookie Setup** – Create visitor cookies and visit the Bilibili home page
5. **Video Details** – Fetch metadata and stats, and build a `video_meta` record
6. **Danmaku** – Download the danmaku XML using `cid` and build `danmaku` records
7. **Comments** – Fetch top comments using `aid` and build `comment` records
8. **Dataset Push** – Push all **Bilibili Video Scraper** records at once
9. **Summary Logging** – Report the total number of items pushed

**Key Benefits:**

- Get video stats, comments, and danmaku in one run
- Use a URL or BV ID, whichever you have
- Receive one dataset with a `type` field to filter records easily
- Automate recurring **Bilibili Video Scraper** runs to track engagement over time

***

### 📥 Input

The Actor accepts the following input parameters:

| Field | Type | Default | Description |
|-------|------|---------|-------------|
| `videoUrlOrBvid` | string | `"BV1uv411q7Mv"` | Bilibili video URL or BV ID. |
| `maxComments` | integer | `30` | Maximum number of danmaku and of comments to collect (each capped at 50). |
| `proxyConfiguration` | object | `{"useApifyProxy": true}` | Apify Proxy configuration. |

**Example Input:**

```json
{
  "videoUrlOrBvid": "BV1uv411q7Mv",
  "maxComments": 30
}
```

**Using a Full Video URL:**

```json
{
  "videoUrlOrBvid": "https://www.bilibili.com/video/BV1uv411q7Mv",
  "maxComments": 50
}
```

**Run Without Proxy:**

```json
{
  "videoUrlOrBvid": "BV1uv411q7Mv",
  "maxComments": 20,
  "proxyConfiguration": {
    "useApifyProxy": True 
  }
}
```

***

### 📤 Output

The Actor pushes **Bilibili Video Scraper** records of three types, identified by the `type` field.

#### **`video_meta` record (1 per run)**

| Field | Type | Description |
|-------|------|-------------|
| `type` | string | `"video_meta"` |
| `bvid` | string | The video's BV ID |
| `aid` | string | The video's numeric AV ID |
| `title` | string | Cleaned video title |
| `description` | string | Cleaned video description |
| `creator_name` | string | Uploader name |
| `creator_mid` | string | Uploader's user ID |
| `views` | integer | View count |
| `likes` | integer | Like count |
| `coins` | integer | Coin count |
| `favorites` | integer | Favorite count |
| `shares` | integer | Share count |
| `danmaku_count` | integer | Total danmaku reported by Bilibili |
| `duration_seconds` | integer | Video length in seconds |
| `pubdate` | string | Publish time in UTC (`YYYY-MM-DD HH:MM:SS`), or `"N/A"` |
| `url` | string | Video page URL |
| `cover_url` | string | Cover image URL |
| `scraped_at` | string | ISO 8601 UTC timestamp |

#### **`danmaku` record**

| Field | Type | Description |
|-------|------|-------------|
| `type` | string | `"danmaku"` |
| `bvid` | string | The video's BV ID |
| `content` | string | Bullet comment text |
| `timepoint_seconds` | number | Time in the video when the bullet comment appears |
| `font_color` | string | Font color value from the source |
| `url` | string | Video page URL |
| `scraped_at` | string | ISO 8601 UTC timestamp |

#### **`comment` record**

| Field | Type | Description |
|-------|------|-------------|
| `type` | string | `"comment"` |
| `bvid` | string | The video's BV ID |
| `rpid` | string | Comment ID |
| `user_name` | string | Commenter's name |
| `user_mid` | string | Commenter's user ID |
| `content` | string | Cleaned comment text |
| `likes` | integer | Likes on the comment |
| `reply_count` | integer | Number of replies to the comment |
| `pubdate` | string | Comment time in UTC, or `"N/A"` |
| `url` | string | Video page URL |
| `scraped_at` | string | ISO 8601 UTC timestamp |

**Example Bilibili Video Scraper Records:**

```json
{
  "type": "video_meta",
  "bvid": "BV1uv411q7Mv",
  "aid": "12345678",
  "title": "Example Video Title",
  "creator_name": "ExampleUploader",
  "views": 1250000,
  "likes": 98000,
  "coins": 45000,
  "favorites": 52000,
  "shares": 8000,
  "danmaku_count": 15000,
  "duration_seconds": 312,
  "pubdate": "2026-05-12 08:30:00",
  "url": "https://www.bilibili.com/video/BV1uv411q7Mv",
  "scraped_at": "2026-10-30T09:00:00Z"
}
```

```json
{
  "type": "danmaku",
  "bvid": "BV1uv411q7Mv",
  "content": "Great video!",
  "timepoint_seconds": 42.5,
  "font_color": "16777215",
  "url": "https://www.bilibili.com/video/BV1uv411q7Mv",
  "scraped_at": "2026-10-30T09:00:00Z"
}
```

***

### 🧰 Technical Stack

- **HTTP Client:** `curl_cffi` with Chrome 124 TLS fingerprint impersonation
- **Sources:** Bilibili video info API, danmaku XML endpoint, and comment API
- **XML Parsing:** Python `xml.etree.ElementTree` for danmaku
- **Text Cleaning:** Regex-based HTML tag removal plus `html.unescape`
- **Date Handling:** `datetime` with timezone-aware UTC timestamps
- **Async:** `asyncio` with executor-run blocking requests
- **Proxy:** Apify Proxy, optional via `useApifyProxy`, with automatic no-proxy fallback on failure
- **Logging:** Apify Actor logging system
- **Platform:** Apify Actor serverless environment

***

### 📊 Data Fields Explained

#### **Video Identity**

- **bvid / aid / title / description**: Identifiers and cleaned text for the video

#### **Creator**

- **creator_name / creator_mid**: The uploader's name and user ID

#### **Engagement**

- **views / likes / coins / favorites / shares / danmaku_count**: Bilibili's engagement statistics for the video

#### **Danmaku**

- **content / timepoint_seconds / font_color**: Bullet comment text, when it appears, and its color

#### **Comments**

- **user_name / content / likes / reply_count / pubdate**: Who commented, what they said, and how the comment performed

***

### 🎯 Use Cases

- **Audience Reaction Analysis** – Read comments and danmaku to understand how viewers respond
- **Sentiment Research** – Feed comment and danmaku text into sentiment analysis tools
- **Content Trend Research** – Compare engagement stats across videos
- **Creator Research** – Review a creator's video performance and audience feedback
- **Social Listening** – Monitor discussions around a specific video
- **Chinese Language Data Collection** – Gather real viewer-generated text for language research

***

### 🚀 Quick Start

#### **1. Prepare Input**

Go to Apify Console and enter:

```json
{
  "videoUrlOrBvid": "BV1uv411q7Mv",
  "maxComments": 30
}
```

#### **2. Run the Actor**

Click **Start**. The Actor will:

- Connect through Apify Proxy if enabled
- Set up visitor cookies
- Fetch video details, danmaku, and top comments
- Push all results to the Dataset as one batch

#### **3. Monitor Progress**

Console shows (the log messages are written in romanized Bengali):

```
🛡️ Apify Proxy connect hoyeche.
🔎 Bilibili video scrape shuru hocche: BV1uv411q7Mv...
💬 Live Danmaku bullet comments ana hocche (cid: ...)...
🗣️ Top comments ana hocche (aid: ...)...
✅ Mot 61 ti Bilibili item dataset e push kora hoyeche!
🎉 Shompurno hoyeche!
```

#### **4. View & Download Results**

- **Results Tab**: All **Bilibili Video Scraper** records
- **Export**: JSON, CSV, Excel, or HTML
- **Filter**: By `type` (`video_meta`, `danmaku`, `comment`)
- **API Access**: Available via the Apify API

***

### ⚙️ Configuration

Default run:

```json
{
  "videoUrlOrBvid": "BV1uv411q7Mv",
  "maxComments": 30
}
```

Maximum items per type:

```json
{
  "videoUrlOrBvid": "BV1uv411q7Mv",
  "maxComments": 50
}
```

Direct connection without proxy:

```json
{
  "videoUrlOrBvid": "BV1uv411q7Mv",
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}
```

***

### 📈 Performance

#### **Processing Speed**

- Four to five lightweight requests per video: home page cookie visit, video details, danmaku XML, and comments
- Results arrive within seconds for a single video

#### **Resource Usage**

- Memory: Low, since no browser instance is launched
- Network: Lightweight requests only
- Proxy: Optional Apify Proxy with automatic no-proxy fallback on failure

***

### ⚠️ Important Notes

#### **Legal & Compliance**

- **Fair Use**: Uses a small number of requests per video to keep load on the source minimal
- **Public Data Only**: Retrieves only publicly available video, comment, and danmaku data
- **Privacy**: Comments include usernames and user IDs, which may be personal data under privacy laws such as GDPR. Use only for legitimate purposes.
- **Legal**: Not legal advice — consult qualified professionals before using this data in compliance-sensitive contexts

#### **Data Quality**

- **One Video Per Run**: Each run processes a single video
- **Limits**: Danmaku and comments are each limited to `min(maxComments, 50)` items per run, so a run returns at most 101 records (1 video record, up to 50 danmaku, up to 50 comments)
- **Danmaku Selection**: Danmaku are taken from the start of the XML file, not sampled across the whole video
- **Comments**: Only top-level comments from the first page are collected; replies to comments are not included, only their count
- **Partial Results**: If danmaku or comments cannot be fetched, the run still returns the video record and any other data it collected
- **Failed Video Lookup**: If the video details cannot be fetched or Bilibili returns an error, the run logs an error and pushes no data
- **Anti-Bot Protection**: Bilibili may block requests at times; using Apify Proxy is recommended
- **Freshness**: Reflects live data at time of run

#### **Best Practices**

- Use a valid, public video URL or BV ID for accurate **Bilibili Video Scraper** results
- Keep Apify Proxy enabled for more reliable access
- Run on a schedule to track changes in views, likes, and comments
- Handle usernames and user IDs responsibly

***

### 📄 License & Legal

**Terms of Use:**

- Use for legitimate research, analytics, and social listening purposes
- Respect Bilibili's terms of service and content creators' rights
- Do not use for spam, harassment, or unlawful data collection
- Use data responsibly and in compliance with applicable privacy laws

**Disclaimer:**
Bilibili Video Scraper is provided as-is for research purposes. It is not affiliated with or endorsed by Bilibili. Users are responsible for compliance with all applicable laws and the terms of service of the data source. This is not legal advice.

***

### ⚖️ Bilibili Video Scraper Excellence

This Actor is optimized for **Bilibili Video Scraper** research with:

- ✅ Video metadata and engagement stats
- ✅ Danmaku (bullet comment) extraction
- ✅ Top comment extraction
- ✅ URL or BV ID input
- ✅ Visitor cookie setup for fewer blocks
- ✅ Proxy fallback for reliable access
- ✅ Production-ready code

# Actor input Schema

## `videoUrlOrBvid` (type: `string`):

Paste the Bilibili video link (e.g. https://www.bilibili.com/video/BV1uv411q7Mv) or just the BVid (e.g. BV1uv411q7Mv).

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

Maximum number of comments and bullet comments to collect.

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

Apify Proxy settings to bypass Bilibili IP rate limits.

## Actor input object example

```json
{
  "videoUrlOrBvid": "https://www.bilibili.com/video/BV1uv411q7Mv",
  "maxComments": 30,
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}
```

# Actor output Schema

## `crawlResults` (type: `string`):

No description

## `suppliersOverview` (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 = {
    "videoUrlOrBvid": "https://www.bilibili.com/video/BV1uv411q7Mv",
    "maxComments": 30
};

// Run the Actor and wait for it to finish
const run = await client.actor("datapilot/bilibili-video-scraper-videos-comments-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 = {
    "videoUrlOrBvid": "https://www.bilibili.com/video/BV1uv411q7Mv",
    "maxComments": 30,
}

# Run the Actor and wait for it to finish
run = client.actor("datapilot/bilibili-video-scraper-videos-comments-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 '{
  "videoUrlOrBvid": "https://www.bilibili.com/video/BV1uv411q7Mv",
  "maxComments": 30
}' |
apify call datapilot/bilibili-video-scraper-videos-comments-danmaku --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,datapilot/bilibili-video-scraper-videos-comments-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/WH4agvh4HghPMLsc4/builds/AMsf8yuPhmKUSGY07/openapi.json
