# 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:** 2 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 a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
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.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use 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

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Bilibili Video Scraper",
        "description": "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.",
        "version": "0.1",
        "x-build-id": "CebEJSsYkXPIpOkxf"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/kjames2001~bilibili-video-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-kjames2001-bilibili-video-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/kjames2001~bilibili-video-scraper/runs": {
            "post": {
                "operationId": "runs-sync-kjames2001-bilibili-video-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/kjames2001~bilibili-video-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-kjames2001-bilibili-video-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "properties": {
                    "searchKeywords": {
                        "title": "Search Keywords",
                        "type": "array",
                        "description": "Keywords to search for on Bilibili. e.g. [\"人工智能\", \"Python教程\"]",
                        "items": {
                            "type": "string"
                        }
                    },
                    "videoUrls": {
                        "title": "Video URLs or BV IDs",
                        "type": "array",
                        "description": "Direct Bilibili video URLs or BV IDs to scrape. e.g. [\"BV1rpWjevEip\", \"https://www.bilibili.com/video/BV1qW4y1a7fU\"]",
                        "items": {
                            "type": "string"
                        }
                    },
                    "maxResults": {
                        "title": "Max Results per Keyword",
                        "minimum": 1,
                        "maximum": 1000,
                        "type": "integer",
                        "description": "Maximum number of videos to scrape per search keyword.",
                        "default": 50
                    },
                    "extractComments": {
                        "title": "Extract Comments",
                        "type": "boolean",
                        "description": "Whether to extract comments for each video.",
                        "default": false
                    },
                    "maxComments": {
                        "title": "Max Comments per Video",
                        "minimum": 1,
                        "maximum": 5000,
                        "type": "integer",
                        "description": "Maximum number of comments to extract per video. Only used if extractComments is true.",
                        "default": 100
                    },
                    "sortBy": {
                        "title": "Sort By",
                        "enum": [
                            "totalrank",
                            "click",
                            "pubdate",
                            "dm",
                            "stow"
                        ],
                        "type": "string",
                        "description": "Sort order for search results.",
                        "default": "totalrank"
                    },
                    "proxyConfiguration": {
                        "title": "Proxy Configuration",
                        "type": "object",
                        "description": "Apify proxy configuration. Use residential proxies if scraping from outside China."
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
