# Bilibili Video Scraper (`kjames2001/bilibili-video-scraper`) Actor

Scrape Bilibili (B站) videos, comments, and creator data by keyword search or direct video URL. 40+ fields per video. No browser needed — uses Bilibili public API directly.

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

## Pricing

Pay per event

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/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## 📺 Bilibili Scraper — B站爬虫 | Video & Comment Data Extraction API

[![Apify Actor](https://img.shields.io/badge/Apify-Actor-blue)](https://apify.com/store)
[![Bilibili API](https://img.shields.io/badge/Bilibili-API-red)](https://www.bilibili.com)
[![Node.js 20](https://img.shields.io/badge/Node.js-20-green)](https://nodejs.org)
[![Pay Per Event](https://img.shields.io/badge/Pricing-Pay_per_Event-orange)](https://apify.com/pricing)

> Scrape **Bilibili** (哔哩哔哩/B站) videos, comments, and creator data by keyword search or direct video URL. The most comprehensive **bilibili scraper** and **bilibili API** tool for data extraction from China's largest video platform — 40+ data fields per video, full comment threads, creator analytics, and danmaku counts. No login required.

### Features

- **Keyword Search** — Search Bilibili videos by keyword, get ranked results with full metadata
- **Direct URL Mode** — Scrape specific videos by BV ID or bilibili.com URL (no login, no cookie)
- **40+ Data Fields** — Title, description, views, likes, coins, favorites, shares, danmaku count, duration, publish date, tags, cover image, and more
- **Comments Scraper** — Extract comments with author info, likes, reply count, timestamps
- **Creator Info** — Author name, avatar, mid, follower stats
- **Sorting Options** — Sort by comprehensive, most viewed, newest, most danmaku, most collected
- **No Browser Needed** — Uses Bilibili's public API directly via the bilibili api, no headless browser required
- **Fast & Efficient** — 500+ videos in under 60 seconds
- **Chinese & English Keywords** — B站爬虫 supports both Chinese and English search terms

### Use Cases

- **Content Research** — Analyze trending topics, video performance benchmarks on B站
- **KOL Discovery** — Find top creators in a niche by engagement metrics
- **Market Research** — Understand Chinese audience interests and content trends
- **Sentiment Analysis** — Extract comments for NLP/sentiment analysis pipelines
- **AI Training Data** — Collect structured Chinese video metadata and comments for LLM fine-tuning
- **Competitive Monitoring** — Track competitor video performance on bilibili.com
- **Academic Research** — Study Chinese digital media patterns and user behavior
- **Social Listening** — Monitor brand mentions and audience reactions across Bilibili videos
- **Price Monitoring** — Track product review videos and consumer sentiment in Chinese markets

### Input Parameters

| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| `searchKeywords` | array | No\* | `["人工智能"]` | Keywords to search on bilibili |
| `videoUrls` | array | No\* | `[]` | Direct BV IDs or bilibili.com URLs |
| `maxResults` | int | No | `50` | Max videos per keyword |
| `extractComments` | bool | No | `false` | Extract comments per video |
| `maxComments` | int | No | `100` | Max comments per video |
| `sortBy` | select | No | `totalrank` | Sort: comprehensive, views, newest, danmaku, favorites |
| `proxyConfiguration` | object | No | Apify proxy | Proxy config (residential recommended outside China) |

\*At least one of `searchKeywords` or `videoUrls` must be provided.

### Output Fields

#### Video Object (40+ fields)

| Field | Type | Description |
|---|---|---|
| `bvid` | string | Bilibili video ID (BV format) |
| `aid` | int | Bilibili video ID (AV format) |
| `title` | string | Video title (HTML tags stripped) |
| `description` | string | Video description |
| `author` | string | Creator name |
| `mid` | int | Creator user ID |
| `authorAvatar` | string | Creator avatar URL |
| `viewCount` | int | Total views |
| `likeCount` | int | Total likes |
| `coinCount` | int | Total coins (Bilibili virtual currency) |
| `favoriteCount` | int | Total favorites |
| `shareCount` | int | Total shares |
| `danmakuCount` | int | Total danmaku (bullet comments) |
| `replyCount` | int | Total comments |
| `duration` | string | Video duration (MM:SS or HH:MM:SS) |
| `publishDate` | string | ISO date string |
| `coverUrl` | string | Cover image URL |
| `tags` | array | Video tags |
| `category` | string | Video category name |
| `url` | string | Video URL on bilibili.com |
| `comments` | array | Comments (if extractComments=true) |

#### Comment Object

| Field | Type | Description |
|---|---|---|
| `commentId` | int | Comment ID |
| `content` | string | Comment text |
| `author` | string | Commenter name |
| `authorMid` | int | Commenter user ID |
| `likes` | int | Comment likes |
| `replyCount` | int | Number of replies |
| `timestamp` | string | ISO date string |

### How It Works

1. **Input your keywords or URLs** — Provide search keywords (e.g., "人工智能", "tech review") or direct BV/AV video URLs
2. **API-based scraping** — The actor calls Bilibili's public search and video info APIs directly (no headless browser)
3. **Optional comment extraction** — If enabled, fetches comment threads via Bilibili's reply API
4. **Structured JSON output** — Results are saved to the Apify dataset as clean, ready-to-use JSON

### Pricing

This Actor uses **pay-per-event** pricing:

| Event | Cost |
|---|---|
| Actor start (1GB RAM) | $0.005 |
| Video scraped | $0.005 |
| Comment extracted | $0.002 |

**Example**: 100 videos with 50 comments each = $0.005 + (100 × $0.005) + (5000 × $0.002) = **$10.505**

### Technical Details

This **bilibili video scraper** uses Bilibili's public API endpoints directly:

- Search: `api.bilibili.com/x/web-interface/search/type`
- Video info: `api.bilibili.com/x/web-interface/view`
- Comments: `api.bilibili.com/x/v2/reply/main`

No headless browser is needed, making it fast and resource-efficient. The **chinese video platform scraper** works with Bilibili's cookie-based access system. Residential proxies are recommended when running from outside China to avoid IP-based rate limiting.

#### Runtime & SDK

- **Runtime:** Node.js 20
- **SDK:** Apify SDK v3 + Crawlee v3
- **Execution:** Single API calls, no browser overhead

### Why Use This vs Alternatives?

| Feature | This Actor | Bilibili Video Search | Bilibili Comments Scraper | TikTok/Douyin/Bilibili Scraper |
|---|---|---|---|---|
| Keyword search | ✅ | ✅ | ❌ | ✅ |
| Direct URL mode | ✅ | ❌ | ✅ | ✅ |
| Comment extraction | ✅ | ❌ | ✅ | ✅ |
| 40+ video fields | ✅ | ❌ | ❌ | ❌ |
| Danmaku counts | ✅ | ✅ | ❌ | ❌ |
| Sorting options | ✅ | ❌ | ❌ | ❌ |
| No login required | ✅ | ✅ | ✅ | ✅ |
| Single-platform focus | ✅ | ✅ | ✅ | ❌ (multi-platform) |

### FAQ

<details>
<summary><b>Do I need a Bilibili account?</b></summary>
No. The actor uses Bilibili's public API and handles cookie-based access automatically.
</details>

<details>
<summary><b>Can I search in Chinese?</b></summary>
Yes. The actor supports both Chinese (B站搜索) and English keywords. Chinese keywords typically return more results.
</details>

<details>
<summary><b>What is danmaku (弹幕)?</b></summary>
Danmaku are "bullet comments" — real-time overlay comments that fly across the video. This is a unique Bilibili feature. The scraper captures the total danmaku count per video.
</details>

<details>
<summary><b>Do I need a proxy?</b></summary>
If running from outside China, residential proxies are recommended to avoid IP-based rate limiting. From within China, the public API works without proxy.
</details>

### Keywords

`bilibili scraper` · `bilibili api` · `b站爬虫` · `bilibili video scraper` · `bilibili comments` · `bilibili data extraction` · `chinese video scraper` · `bilibili search` · `b站视频` · `bilibili crawler` · `bilibili scraper api` · `哔哩哔哩爬虫` · `bilibili video downloader` · `bilibili video data` · `chinese video platform` · `bilibili danmaku` · `bilibili creator data` · `bilibili kol` · `b站视频数据` · `bilibili web scraper` · `china social media scraper` · `bilibili keyword search` · `bilibili bv id` · `bilibili metadata extraction`

# Actor input Schema

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

Keywords to search for on Bilibili. e.g. \["人工智能", "Python教程"]

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

Direct Bilibili video URLs or BV IDs to scrape. e.g. \["BV1rpWjevEip", "https://www.bilibili.com/video/BV1qW4y1a7fU"]

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

Maximum number of videos to scrape per search keyword.

## `extractComments` (type: `boolean`):

Whether to extract comments for each video.

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

Maximum number of comments to extract per video. Only used if extractComments is true.

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

Sort order for search results.

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

Apify proxy configuration. Use residential proxies if scraping from outside China.

## Actor input object example

```json
{
  "searchKeywords": [
    "人工智能"
  ],
  "videoUrls": [],
  "maxResults": 50,
  "extractComments": false,
  "maxComments": 100,
  "sortBy": "totalrank",
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}
```

# 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": [
        "人工智能"
    ],
    "videoUrls": [],
    "proxyConfiguration": {
        "useApifyProxy": true
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("kjames2001/bilibili-video-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 = {
    "searchKeywords": ["人工智能"],
    "videoUrls": [],
    "proxyConfiguration": { "useApifyProxy": True },
}

# Run the Actor and wait for it to finish
run = client.actor("kjames2001/bilibili-video-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).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": [
    "人工智能"
  ],
  "videoUrls": [],
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}' |
apify call kjames2001/bilibili-video-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=kjames2001/bilibili-video-scraper",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/PDHpfadj2NDJxVgL1/builds/w3MUaDvraxTJmQo6L/openapi.json
