탐색으로 건너뛰기

Use Python to find Bilibili tutorials and turn comments into course improvements

To learn how comparable Bilibili tutorials organize their steps and where viewers get stuck, run the Python script bili_read.py: save one search page with bilibili.web.fetch_general_search, select the relevant videos by hand, read each selected video’s comments with bilibili.app.fetch_video_comments, and hand off a course-improvement list.

bili_read.py uses only the Python 3 standard library and sends one request per run. With a verified BV ID, start at the comment step; with original responses already saved, reuse the saved responses.

1. Plan scope and environment

  1. Set BEATAPI_API_KEY in your local environment.
  2. Plan one search page, then two or three videos that match the course topic and software version, with one comment page per video. Three selected videos mean up to four queries, each charged at the current action price on the pricing page.

The search request uses most-played ordering, order: click, to discover candidates. Select videos by their relevance to your course, not by play count.

2. Save one request and response

Save the script below as bili_read.py. The search mode calls bilibili.web.fetch_general_search; the comments mode calls bilibili.app.fetch_video_comments. Each run creates a new directory for the request and the original response.

import json
import os
import sys
from datetime import datetime, timezone
from pathlib import Path
from urllib.error import HTTPError, URLError
from urllib.request import Request, urlopen
if len(sys.argv) != 4 or sys.argv[1] not in {"search", "comments"}:
raise SystemExit("Usage: python3 bili_read.py search|comments VALUE NEW_DIRECTORY")
mode, value, directory = sys.argv[1:]
if not value.strip():
raise SystemExit("Supply a keyword or a verified BV ID")
key = os.environ.get("BEATAPI_API_KEY")
if not key:
raise SystemExit("Set BEATAPI_API_KEY in your local environment")
if mode == "search":
action = "bilibili.web.fetch_general_search"
params = {"keyword": value, "order": "click", "page": 1, "page_size": 20}
else:
action = "bilibili.app.fetch_video_comments"
params = {"bv_id": value, "mode": 3, "next_offset": 1}
body = {"action": action, "params": params}
out = Path(directory)
out.mkdir(parents=True, exist_ok=False)
(out / "request.json").write_text(json.dumps(body, ensure_ascii=False, indent=2), encoding="utf-8")
started = datetime.now(timezone.utc).isoformat()
(out / "attempt.json").write_text(json.dumps({"started_at": started, "action": action}), encoding="utf-8")
request = Request("https://api.beatapi.io/v1/social-data/call",
data=json.dumps(body).encode("utf-8"), method="POST",
headers={"Authorization": "Bearer " + key, "Content-Type": "application/json"})
try:
with urlopen(request, timeout=60) as response:
status, raw = response.status, response.read()
except HTTPError as error:
status, raw = error.code, error.read()
except URLError:
(out / "transport-error.json").write_text(json.dumps({"outcome": "unknown", "action": action}), encoding="utf-8")
raise SystemExit("No final response saved; review the attempted request before repeating")
(out / "response.json").write_bytes(raw)
(out / "call.json").write_text(json.dumps({"action": action, "params": params,
"http_status": status, "started_at": started,
"finished_at": datetime.now(timezone.utc).isoformat(),
"response_file": "response.json", "platform_review": "required"},
ensure_ascii=False, indent=2), encoding="utf-8")
try:
payload = json.loads(raw)
except (ValueError, UnicodeError):
raise SystemExit("Saved a non-JSON response; inspect response.json")
if status != 200 or not isinstance(payload, dict) or payload.get("status") != "succeeded" or payload.get("error") is not None or payload.get("action") != action:
raise SystemExit("Saved a failed or unexpected response; inspect response.json")
print("Saved response for platform-content review: " + str(out / "response.json"))

Retrieve an initial candidate page:

python3 bili_read.py search 'video editing tutorial' bili-search-01

The output directory holds request.json, attempt.json, call.json and response.json. bili_read.py checks the public execution envelope and marks platform_review: required in call.json, because you still review the platform content yourself. The script saves every HTTP body as returned. When the network drops before a final response, the script records the attempt in transport-error.json and does not retry automatically.

3. Choose videos worth reading

  1. Review the results. Check each search result’s title, creator, video and topic in response.json.
  2. Select. Keep videos with concrete steps, demonstrations or useful discussion. Record the exclusion reason for videos on a different software version, promotional material and namesakes.
  3. Record. For each selected video, save the verified BV ID, source, selection reason and collection time. Copy counts exactly as returned; leave missing values blank and do not substitute another metric.

The search order parameter accepts totalrank for comprehensive, click for plays, pubdate for latest, dm for bullet comments and stow for favorites. To find new-version tutorials, run a separate pubdate search and save each round’s conditions; do not treat the two result sets as one observation.

4. Read selected comments

Pass the verified BV ID and a new directory:

python3 bili_read.py comments '<confirmed_bv_id>' bili-comments-01

The comments mode requests popular App comments with mode: 3 and the first page with next_offset: 1. For time order, change mode to 2; see comment ordering. Each run reads only the first batch and does not continue to later pages or change the ordering.

Read the concrete questions first, then expand replies where needed. A comment about a missing menu needs version context; a comment about a silent step may need media and track information. Keep parent relationships and video sources with the teaching-table workflow.

5. Build the next course-improvement list

ItemHow to use it
Helpful explanation approachSpecific video, step or wording and why it clarifies the task
Learning questionExact comment, conditions, source video and relevant replies
Existing explanationSupporting video passage or reply
Proposed changeVersion note, demonstration, exercise or conditions to clarify first
ScopeVideos and comment pages actually read, plus unfinished material

For example, explaining prerequisites before a demonstration is a structure worth reusing. Check each specific step against your own software version and learning goal; do not copy titles or only count topic words.

Use the CSV example in the comment export FAQ to export source comments and course improvements as separate sheets. A backlog item can cite several comments or point to a lesson that already answers the question. Before handing the sheets to a teammate, pick one backlog item and follow the item’s references back to the comments and videos.

For the assistant:

Reuse these search and comment originals to select tutorials matching our version and task. Record explanation structure and viewer wording. Attach sources and reasons to each improvement, identify missing context, and distinguish reference approaches, open questions and updates ready to make.

Act on the first findings before adding videos or pages. bili_read.py runs once per call; set up recurring runs, storage and notifications in your own task environment if you need them.

Comments to teaching work · BV/AV identity