<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[lexang]]></title><description><![CDATA[lexang]]></description><link>https://lexang.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Tue, 01 Dec 2026 00:05:46 GMT</lastBuildDate><atom:link href="https://lexang.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Turn a Bilibili JSON export into a creator review sheet with Python]]></title><description><![CDATA[Group Bilibili video exports by creator ID, track missing metrics, and export CSV or Excel review sheets with Python. Includes an offline example.]]></description><link>https://lexang.hashnode.dev/turn-a-bilibili-json-export-into-a-creator-review-sheet-with-python</link><guid isPermaLink="true">https://lexang.hashnode.dev/turn-a-bilibili-json-export-into-a-creator-review-sheet-with-python</guid><category><![CDATA[Python]]></category><category><![CDATA[data analysis]]></category><category><![CDATA[json]]></category><dc:creator><![CDATA[Zhang Lixiang]]></dc:creator><pubDate>Fri, 06 Nov 2026 15:24:35 GMT</pubDate><content:encoded><![CDATA[<p>A video search export gives you video rows. If you want to review the creators behind those videos, counting display names isn't enough: one creator can appear several times, and different people can use the same name.</p>
<p>In an existing 20-video mechanical-keyboard search test, grouping by creator ID produced 19 groups. That is the number of creators represented in the file, not the number of keyboard creators on Bilibili. I hadn't fetched their profiles or full upload histories.</p>
<p>I maintain the paid Bilibili Scraper on Apify and the companion analysis code used here. This walkthrough starts offline. You can run the included synthetic fixture without an Apify account or a paid collection, then import an export you are allowed to process.</p>
<p><a href="https://github.com/lexang/bilibili-data-analysis">https://github.com/lexang/bilibili-data-analysis</a></p>
<h2>Run the synthetic fixture first</h2>
<p>Download the repository. From its directory, using Python 3.10 or later:</p>
<pre><code class="language-shell">python analyze.py
python -m unittest -v test_example
</code></pre>
<p>The script reads <code>data/synthetic-videos.json</code> and creates a new <code>output</code> directory. CSV export uses Python's standard library. The tests block real socket connections; without the optional Excel dependencies, the Excel test is skipped.</p>
<p>The nine fabricated records include a duplicate video ID, a non-video record and an invalid identifier. Six video-format records survive validation and deduplication, producing four creator-ID groups and three video review rows. These counts exercise the code, not a research finding. Synthetic video and profile links stay blank, and the outputs carry <code>is_synthetic</code> markers.</p>
<p>The script refuses to overwrite an existing output directory. For a second run, choose a new one:</p>
<pre><code class="language-shell">python analyze.py --output-dir second-analysis
</code></pre>
<h2>Keep the grouping key separate from the name</h2>
<p>The first pass keeps the first record for each valid <code>bvid</code>. Later duplicates are skipped, not merged into a newer snapshot. The creator pass groups those unique video rows by <code>authorMid</code>, the numeric creator ID. Bilibili calls a creator an <code>UP主</code>.</p>
<p>Two records in the synthetic fixture share a display name but have different creator IDs. They remain separate groups. Two videos with the same ID go into the same group even if a display name changes. Names are labels for review, not identity keys.</p>
<p>Creator IDs remain strings in the tables. The fixture includes IDs above JavaScript's safe-integer range to check that export handling preserves them. That doesn't mean real Bilibili IDs need to be that large. If another tool has already rounded an ID, converting it to a string cannot restore the original digits.</p>
<h2>Read the creator table with its coverage columns</h2>
<p>Open <code>creators.csv</code>. It is a summary of this input file, not a fetched creator profile.</p>
<table>
<thead>
<tr>
<th>Column</th>
<th>What it tells you</th>
</tr>
</thead>
<tbody><tr>
<td><code>sample_video_count</code></td>
<td>Unique videos assigned to this ID in the file</td>
</tr>
<tr>
<td><code>observed_views_sum</code></td>
<td>Sum of available, valid view counts</td>
</tr>
<tr>
<td><code>videos_with_views</code></td>
<td>Number of videos contributing to that sum</td>
</tr>
<tr>
<td><code>observed_likes_sum</code>, <code>videos_with_likes</code></td>
<td>The corresponding observed like sum and coverage</td>
</tr>
<tr>
<td><code>representative_bvid</code>, <code>representative_views</code></td>
<td>The group's highest-view video among measured rows; an ID tie-breaker makes the choice deterministic</td>
</tr>
<tr>
<td><code>profile_url</code>, <code>profile_status</code></td>
<td>For imported data, a URL constructed from the ID, marked as not visited</td>
</tr>
</tbody></table>
<p>The synthetic two-video group has 2,000 and 800 views, so its observed sum is 2,800 with coverage of two videos. One like count is missing, so its like sum covers only one video. Another group has no measured view count; its sum is blank. A valid zero stays zero.</p>
<p>Read a sum together with its coverage. It cannot tell you the creator's total views, follower count, unique audience or sales. The table sorts by observed sample view sums for convenience; that order is not an influencer recommendation.</p>
<p><code>has_review_candidate</code> means the group has at least one video meeting the example's 1,000-view threshold. It does not mean the creator has been checked for audience fit. The separate <code>review.csv</code> also requires a known favorites count and orders video rows by favorites/views. These are different checks; neither establishes commercial suitability.</p>
<h2>Import your own JSON without collecting again</h2>
<p>Provide a JSON array with the Actor's video fields, including <code>type</code>, <code>bvid</code> and <code>authorMid</code>:</p>
<pre><code class="language-shell">python analyze.py --input path/to/videos.json --output-dir imported-analysis
</code></pre>
<p>The script reads that file without visiting the video or creator links. It rejects files mixing synthetic and unmarked records. Do not add <code>is_synthetic: true</code> to real data.</p>
<p>The original author-test file produced 20 unique video rows, 19 creator groups and 10 video review rows. Those are historical offline results, not a new collection or customer case. The repository deliberately excludes that file and its real-data CSV/Excel outputs. Its bundled fixture is a separate fabricated dataset.</p>
<p>Before treating any row as a creator candidate, open the permitted source links yourself. Check the topic, publication date, recent relevant uploads and any disclosed commercial relationship. None of those checks has been completed by this script. A generated profile URL isn't proof that the profile is available.</p>
<h2>Add Excel when you need it</h2>
<p>CSV output uses UTF-8 with a BOM. Formula-like external text gets an apostrophe prefix in exported tables; the source JSON remains unchanged. Excel is an optional output using the repository's pinned dependencies:</p>
<pre><code class="language-shell">python -m pip install -r requirements-excel.txt
python analyze.py --excel --output-dir excel-analysis
</code></pre>
<p>Dependency installation downloads packages; it does not start the Actor. The workbook contains <code>videos</code>, <code>review</code> and <code>creators</code> sheets alongside the CSV files. Check <code>summary.json</code> for the source hash, missing-count audit and whether the input was synthetic or imported.</p>
<h2>If you need a new export</h2>
<p>The paid Actor can collect public video metadata. Running it normally requires an Apify account, but you supply no Bilibili account login cookies; it manages guest cookies internally. Video and creator-profile records each cost $0.002, or $2 per 1,000, with platform usage included for the run. Exactly 20 returned videos at that listed price cost $0.04. Check the Store price, permissions and charge limit before a collection.</p>
<p><a href="https://apify.com/zlexang/bilibili-scraper-no-login">https://apify.com/zlexang/bilibili-scraper-no-login</a></p>
<p>For the earlier keyword-search walkthrough, including the limits of the 20-video relevance sample:</p>
<p><a href="https://lexang.hashnode.dev/sorting-bilibili-videos-with-python-a-20-result-keyboard-research-sample">https://lexang.hashnode.dev/sorting-bilibili-videos-with-python-a-20-result-keyboard-research-sample</a></p>
<p>No new run is needed to follow this article. The metadata tool does not download videos, subtitles or comment text. Public visibility doesn't grant redistribution, commercial-use or AI-training rights; assess your intended use before storing or sharing an export. Start by checking what is actually in the file and which creator facts are still missing.</p>
]]></content:encoded></item><item><title><![CDATA[Sorting Bilibili videos with Python: a 20-result keyboard research sample]]></title><description><![CDATA[Export 20 Bilibili search results, filter low-view videos, and use Python to create a CSV review list without treating engagement as sales.]]></description><link>https://lexang.hashnode.dev/sorting-bilibili-videos-with-python-a-20-result-keyboard-research-sample</link><guid isPermaLink="true">https://lexang.hashnode.dev/sorting-bilibili-videos-with-python-a-20-result-keyboard-research-sample</guid><category><![CDATA[Python]]></category><category><![CDATA[data analysis]]></category><dc:creator><![CDATA[Zhang Lixiang]]></dc:creator><pubDate>Wed, 04 Nov 2026 11:56:39 GMT</pubDate><content:encoded><![CDATA[<p>Half of the 20 videos in my Bilibili search sample had fewer than 1,000 views. Nine titles mentioned magnetic switches. Those two details mattered when deciding which videos to review: the results mixed different levels of reach and different kinds of keyboards.</p>
<p>The search term was <code>机械键盘</code>, Chinese for "mechanical keyboard". I exported the results as JSON and used Python to make a review list. The script below needs only the standard library.</p>
<p>I developed the Bilibili Scraper used to collect this sample and sell it on Apify. You can also run the analysis on data you have permission to use, provided it has the same fields.</p>
<h2>Collect a small sample</h2>
<p><a href="https://apify.com/zlexang/bilibili-scraper-no-login/examples/bzhan-guan-jian-ci-sou-suo-shi-li-zui-duo-20tiao?utm_source=hashnode&amp;utm_medium=article&amp;utm_campaign=bilibili_keyword_research">This example task</a> searches for <code>机械键盘</code>, sorts by relevance, and returns up to 20 video records. You need an Apify account to copy and run it, but no Bilibili login or cookies. This configuration uses no proxy and leaves video-detail enrichment off.</p>
<pre><code class="language-json">{
  "searchKeywords": ["机械键盘"],
  "maxResultsPerKeyword": 20,
  "searchOrder": "totalrank",
  "enrichSearchResults": false,
  "includePopular": false,
  "proxyConfiguration": {"useApifyProxy": false}
}
</code></pre>
<p>After signing in, copy the task, change the keyword if needed, and run it. On the output page, select Export and download the JSON as <code>keyword-demo-results.json</code>. You can also export CSV or Excel.</p>
<p>The November 4, 2026 run returned 20 distinct video URLs in about six seconds. Titles, creator names, views, likes, favorites, and publication times were present in all 20 records. That is the timing for one small run. Other keywords or larger batches may hit rate limits.</p>
<p>Pricing is $0.002 per video or creator profile, or $2 per 1,000 records, with platform usage included. At that rate, a customer run returning 20 videos costs $0.04. This was my own development test, not a sale; its rounded cost display is not a customer bill or evidence of free use.</p>
<h2>Make a review list</h2>
<p>The filter keeps videos with at least 1,000 views, then sorts them by <code>favorites / views</code>. Very small view counts can give a few favorites a large ratio. I chose 1,000 to limit that effect in this sample; it is not a general research standard.</p>
<p>Save the script beside <code>keyword-demo-results.json</code> and run it with Python:</p>
<pre><code class="language-python">import csv
import json
from pathlib import Path

rows = json.loads(Path("keyword-demo-results.json").read_text(encoding="utf-8"))
review = []

for row in rows:
    views = row.get("views")
    favorites = row.get("favorites")
    if not isinstance(views, (int, float)) or views &lt; 1000:
        continue
    if not isinstance(favorites, (int, float)) or favorites &lt; 0:
        continue
    review.append({
        "title": row["title"],
        "authorName": row["authorName"],
        "views": views,
        "favorites": favorites,
        "favorite_pct": round(100 * favorites / views, 2),
        "publishedAt": row["publishedAt"],
        "url": row["url"],
    })

review.sort(key=lambda row: row["favorites"] / row["views"], reverse=True)

with open("review.csv", "w", encoding="utf-8-sig", newline="") as stream:
    writer = csv.DictWriter(stream, fieldnames=[
        "title", "authorName", "views", "favorites",
        "favorite_pct", "publishedAt", "url",
    ])
    writer.writeheader()
    writer.writerows(review)

print(f"Rows to review: {len(review)}")
</code></pre>
<p>The script writes 10 rows to <code>review.csv</code>, sorted by the unrounded ratio. Only the displayed percentage is rounded. Bilibili calls creators "UP主"; the <code>authorName</code> field keeps their names in Chinese so you can match them to the source records.</p>
<table>
<thead>
<tr>
<th>Creator</th>
<th align="right">Views</th>
<th align="right">Favorites</th>
<th align="right">Favorites / views</th>
</tr>
</thead>
<tbody><tr>
<td>键盘推荐2026</td>
<td align="right">156954</td>
<td align="right">3133</td>
<td align="right">2.00%</td>
</tr>
<tr>
<td>搞机研玩社</td>
<td align="right">119813</td>
<td align="right">2311</td>
<td align="right">1.93%</td>
</tr>
<tr>
<td>歪设长</td>
<td align="right">337386</td>
<td align="right">3818</td>
<td align="right">1.13%</td>
</tr>
</tbody></table>
<p>These counts are a snapshot from the collection time. The percentage is calculated locally. It isn't an official Bilibili conversion rate, a measure of buying intent, or a sales estimate. It gives me an order in which to open the links.</p>
<h2>Review the videos behind the numbers</h2>
<p>For product research, I would open each URL and record the price range, keyboard layout, switch type, and use case being discussed. A title that says "review" or "tested" still needs checking against the video itself. Sponsorship also needs a separate check.</p>
<p>The nine titles mentioning magnetic switches tell us that this search includes that category. They don't tell us its market share. Relevance-ranked search results are not a random sample, and 20 records are too few for a conclusion about the whole keyboard market.</p>
<p>If the purpose is creator research, the CSV is only a starting point. Recent uploads, audience fit, and public contact information need separate review. I kept <code>publishedAt</code> because an older video has had more time to accumulate views than a new one.</p>
<p>For recent content, change <code>searchOrder</code> to <code>pubdate</code> and collect another sample. I haven't run that second query for this article. When combining searches, deduplicate by <code>bvid</code> or URL before counting videos.</p>
<h2>Missing fields and collection limits</h2>
<p>Search results can have <code>null</code> values for <code>coins</code> and <code>shares</code>. Missing is not zero. The optional <code>enrichSearchResults</code> mode fetches extra details and makes more requests; this demonstration did not test that mode.</p>
<p>The tool collects public video metadata. It does not download videos or collect comment text, members-only content, or other non-public material. Public visibility does not grant unrestricted collection, redistribution, or commercial-use rights. Check the platform's terms, your data permissions, and applicable law before collecting. Reduce the scope or stop when access is restricted; don't try to bypass verification challenges.</p>
<p>The <a href="https://apify.com/zlexang/bilibili-scraper-no-login?utm_source=hashnode&amp;utm_medium=article&amp;utm_campaign=bilibili_keyword_research">tool page</a> lists its fields and input options. For a different research question, decide which fields you need and what you will check manually before increasing the result limit.</p>
]]></content:encoded></item></channel></rss>