Bilibili API in Python: videos and comments (2026)

Bilibili's open platform is for uploaders managing their own channel, with no search among its scopes; the web pages' endpoints need a wbi signature and answer 412 once requests come fast. To search videos and read comments from a program, use a third-party data API. Below it is done with DataXAPI's Python SDK; the free trial covers up to 333 calls. 2 endpoints do it: Bilibili video search → Bilibili video comments. The worked example below is 11 calls and costs $0.0220 in all; a failed call is not charged.

Updated 2026-11-06Open in ChatGPTOpen in Claude

Search a page of Bilibili videos on a keyword, take the top comments under the 10 most played, into one CSV: BV id, title, plays, comment text, comment likes.

Step 1: Bilibili video search

A page of videos for the search terms; sort can be newest or most played. Each item's id is its BV id and metrics.views its plays.

curl -G "https://api.dataxapi.com/v1/bilibili/videos/search" \
  --data-urlencode "query=机械键盘" \
  -H "Authorization: Bearer $DATAXAPI_API_KEY"
# pip install dataxapi
from dataxapi import DataXAPI

dx = DataXAPI()  # reads DATAXAPI_API_KEY
result = dx.bilibili.videos.search(query="机械键盘")
print(result["data"]["items"])
// npm i @dataxapi/sdk
import { DataXAPI } from "@dataxapi/sdk";

const dx = new DataXAPI(); // reads DATAXAPI_API_KEY
const result = await dx.bilibili.videos.search({ query: "机械键盘" });
console.log(result.data.items);
dataxapi call bilibili.videos.search 'query=机械键盘'
Recorded response
{
  "code": "ok",
  "request_id": "dee21d14-3682-420a-acad-8806b2d59dfe",
  "data": {
    "items": [
      {
        "id": "BV1M05Rhoe4r",
        "url": "https://www.bilibili.com/video/BV1M05Rhoe4r",
        "type": "video",
        "title": "实测一个月机械键盘,结论有点意外",
        "text": null,
        "published_at": "2026-09-30T08:55:00.000Z",
        "author": {
          "id": "585724901",
          "name": "阿杰爱折腾",
          "avatar_url": "https://i0.hdslb.com/bfs/face/17a7658e63c84808ef09bb48.jpg"
        },
        "metrics": {
          "likes": 237,
          "comments": 64,
          "favorites": 169,
          "views": 35706
        },
        "hashtags": [
          "户外生活",
          "好物分享",
          // … 8 more
        ]
      },
      // … 19 more
    ]
  },
  "page": {
    "next_cursor": "c1.72NAeDsxx6zMLTUXCjX2T5Su39puxExBbLOvdWBm",
    "cursor_expires_at": "2026-10-12T19:47:48.000Z",
    "has_more": true,
    "returned": 20
  },
  "warnings": [],
  "meta": {
    "capability": "bilibili.videos.search",
    "result_status": "complete",
    "fetched_at": "2026-10-12T18:47:48.000Z",
    "cached": false,
    "replayed": false,
    "unavailable": {
      "lang": "capability",
      "author.username": "platform",
      "author.verified": "capability",
      "author.followers": "capability",
      "metrics.shares": "capability",
      "metrics.reposts": "platform",
      "images": "platform",
      "mentions": "capability",
      "is_pinned": "capability",
      "post_id": "platform",
      "parent_id": "platform",
      "root_id": "platform"
    },
    "billing": {
      "amount": "0.002",
      "currency": "USD",
      "balance_after": "9.998"
    }
  }
}

From a response recorded 2026-10-12 18:47 UTC. Names, text and IDs are examples, and so are the links: none is the recorded one (the page shows no one's personal data); the figures are as recorded. Long lists are cut. The request ID, cursor and balance are made up.

Bilibili video search · $0.0020 / a call · Parameters, fields and errors on the endpoint's page →

Step 2: Bilibili video comments

Put the BV id into id for a page of about 20 comments, most popular first; the next page comes from page.next_cursor.

curl -G "https://api.dataxapi.com/v1/bilibili/videos/comments/list" \
  --data-urlencode "id=BV1ECeJ65EZS" \
  -H "Authorization: Bearer $DATAXAPI_API_KEY"
# pip install dataxapi
from dataxapi import DataXAPI

dx = DataXAPI()  # reads DATAXAPI_API_KEY
result = dx.bilibili.videos.comments.list(id="BV1ECeJ65EZS")
print(result["data"]["items"])
// npm i @dataxapi/sdk
import { DataXAPI } from "@dataxapi/sdk";

const dx = new DataXAPI(); // reads DATAXAPI_API_KEY
const result = await dx.bilibili.videos.comments.list({ id: "BV1ECeJ65EZS" });
console.log(result.data.items);
dataxapi call bilibili.videos.comments.list id=BV1ECeJ65EZS
Recorded response
{
  "code": "ok",
  "request_id": "ffe3c01c-df20-4815-8524-b01f20752e0e",
  "data": {
    "items": [
      {
        "id": "284891776844",
        "text": "终于有人讲清楚了,谢谢博主",
        "published_at": "2026-10-09T09:14:53.000Z",
        "author": {
          "id": "555745700",
          "username": null,
          "name": "认真生活的阿雅",
          "avatar_url": "https://i0.hdslb.com/bfs/face/4dcb12b520f2d37bad6e39ea.jpg"
        },
        "metrics": { "likes": 730, "comments": 16 },
        "post_id": "BV1D1g8QchPg",
        "parent_id": null,
        "root_id": null
      },
      // … 19 more
    ]
  },
  "page": {
    "next_cursor": "c1.6b2UBLUHWAibmZ7ga14nI9P9jZqzDeOQTFrW_ENB",
    "cursor_expires_at": "2026-10-12T19:43:21.000Z",
    "has_more": true,
    "returned": 20
  },
  "warnings": [],
  "meta": {
    "capability": "bilibili.videos.comments.list",
    "result_status": "complete",
    "fetched_at": "2026-10-12T18:43:21.000Z",
    "cached": false,
    "replayed": false,
    "unavailable": { "url": "platform" },
    "billing": {
      "amount": "0.002",
      "currency": "USD",
      "balance_after": "9.998"
    }
  }
}

From a response recorded 2026-10-12 18:43 UTC. Names, text and IDs are examples, and so are the links: none is the recorded one (the page shows no one's personal data); the figures are as recorded. Long lists are cut. The request ID, cursor and balance are made up.

Bilibili video comments · $0.0020 / a call · Parameters, fields and errors on the endpoint's page →

What the example costs

One page of search results, then a page of comments under 10 videos

EndpointCallsPriceSubtotal
Bilibili video search1$0.0020$0.0020
Bilibili video comments10$0.0020$0.0200
Total11$0.0220

Prices are the prices in force when this page was built. A failed call costs nothing.

In your AI (MCP)

Connect DataXAPI to your AI client once. Then say what you want; the agent finds these endpoints, checks the price and calls them on your balance.

Say: Search Bilibili for 机械键盘 (mechanical keyboard), take the 10 most played videos and list their top comments as one table.
What the agent sends to the call tool
{
  "capability": "bilibili.videos.search",
  "query": "机械键盘",
  "idempotency_key": "<a new UUID>"
}

Sign in to copy the setup prompt with your keyAbout the MCP server →

With a Skill

Why DataXAPI

  • Steady: endpoints were available 100% of the last 30 days, on a public status page you can check.
  • Fast: a paid call took 1.6 seconds at the median over the last 7 days (counted 2026-11-06).
  • Fewer tokens: across 9 endpoints on Bilibili, one recorded real response each, the platform's own JSON comes to 477k tokens and what an AI reads through DataXAPI's MCP server to 21k, 96% fewer; the JSON of a direct API call is 95% fewer too (counted 2026-11-06). Every platform answers in one shape: the author in author, counts in metrics, the next page in page.next_cursor, so another platform needs no new parser.
  • See before you pay: every endpoint's page shows a recorded real response, field by field.
  • Spending you control: a failed call is not charged; each key can have a limit, X-Max-Price caps one call, and the same Idempotency-Key within 24 hours is never charged twice.
  • Ready for AI: a remote MCP server listed in the official MCP registry as com.dataxapi/mcp, usable from Claude, Cursor and ChatGPT.
  • Free trial of up to 333 calls, no card.

Good to know

  • No Bilibili account or cookie, and no wbi signature.
  • An uploader's videos come from bilibili.users.videos.list, by mid (the digits in their space link).
  • Without code: connect DataXAPI to Claude or ChatGPT and say the sentence under “In your AI”.

The whole script

The task above as one script that runs as it is: Python, the SDK, your key from DATAXAPI_API_KEY. It writes a CSV file and ends by printing what it called, fetched and was charged.

Python
# pip install dataxapi
# export DATAXAPI_API_KEY=dx_...   (your key)
import csv
from decimal import Decimal
from dataxapi import DataXAPI

dx = DataXAPI()
calls, fetched, charged = 0, 0, Decimal("0")

def run(capability, params):
    """One call; counts it and what it was charged."""
    global calls, charged
    result = dx.call(capability, params)
    calls += 1
    charged += Decimal(str(result["meta"]["billing"]["amount"]))
    return result

QUERY = "机械键盘"
VIDEOS = 10

# 1. A page of videos for the search terms; the most played first.
videos = run("bilibili.videos.search", {"query": QUERY})["data"]["items"]
videos = sorted(videos, key=lambda each: -(each["metrics"].get("views") or 0))[:VIDEOS]

# 2. The first page of comments under each, the most popular first.
rows = []
for video in videos:
    for comment in run("bilibili.videos.comments.list", {"id": video["id"]})["data"]["items"]:
        rows.append([video["id"], video.get("title"), video["metrics"].get("views"), comment.get("text"), comment["metrics"].get("likes")])

fetched = len(rows)
with open("bilibili-comments.csv", "w", newline="", encoding="utf-8") as file:
    csv.writer(file).writerows([["bvid", "title", "plays", "comment", "comment_likes"], *rows])

print(f"calls: {calls}, items: {fetched}, charged: ${charged}")