Skip to main content

BiliHome

一个用于获取B站用户信息的Python包

功能特性

  • 获取B站用户的粉丝数量
  • 获取B站用户的关注数量
  • 获取B站用户的用户名
  • 简单易用的API接口
  • 自动处理网络请求异常

安装

使用pip安装(推荐)

pip install BiliHome

从源码安装

git clone https://github.com/Moxin1044/BiliHome.git
cd BiliHome
pip install .

快速开始

基本用法

from BiliHome import Bili

# 创建Bili实例(使用用户的vmid)
bili_user = Bili("8047632")

# 获取粉丝数量
fans_count = bili_user.fans()
print(f"粉丝数量: {fans_count}")

# 获取关注数量
follows_count = bili_user.follows()
print(f"关注数量: {follows_count}")

# 获取用户名
username = bili_user.name()
print(f"用户名: {username}")

完整示例

#!/usr/bin/env python3
"""
BiliHome使用示例
"""

import sys
import os

# 添加当前目录到Python路径,以便导入BiliHome包
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

from BiliHome import Bili

def main():
    """主函数"""
    print("BiliHome示例程序")
    
    # 使用示例中的vmid
    vmid = "8047632"
    
    # 创建Bili实例
    bili_user = Bili(vmid)
    
    # 获取粉丝数量
    fans_count = bili_user.fans()
    
    if fans_count is not None:
        print(f"用户 {vmid} 的粉丝数量: {fans_count}")
    else:
        print("获取粉丝数量失败,请检查网络连接或vmid是否正确")
    
    # 获取关注数量
    follows_count = bili_user.follows()
    if follows_count is not None:
        print(f"用户 {vmid} 的关注数量: {follows_count}")
    else:
        print("获取关注数量失败,请检查网络连接或vmid是否正确")

    # 获取用户名
    username = bili_user.name()
    if username is not None:
        print(f"用户 {vmid} 的用户名: {username}")
    else:
        print("获取用户名失败,请检查网络连接或vmid是否正确")

if __name__ == "__main__":
    main()

API文档

Bili类

构造函数

Bili(vmid)

参数:

  • vmid (str): B站用户的唯一标识符(个人主页ID)

方法

fans()

获取用户的粉丝数量

返回值:

  • int: 用户的粉丝数量,如果请求失败返回None
follows()

获取用户的关注数量

返回值:

  • int: 用户的关注数量,如果请求失败返回None
name()

获取用户的用户名

返回值:

  • str: 用户名称,如果获取失败返回None

运行测试

项目包含一个测试文件,可以验证包的功能:

python test_bili.py

依赖

  • Python 3.6+
  • requests >= 2.25.0

许可证

MIT License

贡献

欢迎提交Issue和Pull Request来改进这个项目。

支持

如果您在使用过程中遇到问题,请通过以下方式联系:

版本历史

  • v0.1.0 (当前版本)
    • 初始版本发布
    • 支持获取粉丝数量、关注数量和用户名

注意事项

  1. 请确保网络连接正常,因为所有数据都通过B站API获取
  2. 请遵守B站的使用条款和API调用频率限制
  3. 如果遇到请求失败,请检查网络连接和vmid是否正确
  4. 本工具仅用于学习和开发目的,请勿用于商业用途

Metadata

Release files for BiliHome 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for BiliHome 0.1.0
File Size Uploaded Provenance Actions
bilihome-0.1.0.tar.gz 4.9 kB With provenance Details for bilihome-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for BiliHome 0.1.0
File Interpreter ABI Platform Actions
bilihome-0.1.0-py3-none-any.whl Python 3 none any Details for bilihome-0.1.0-py3-none-any.whl

Total release size: 10.0 kB

Release files / bilihome-0.1.0.tar.gz

Download URL bilihome-0.1.0.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
452cb371ead54f4904cfb2b0eee44fd63bc5dd1b6baf5a76be6d620339a0c122
BLAKE2b-256 checksum
How to use checksums
fcbd29312374d861331cc63e192c4bb251ef677e0d9aa0b595741a001b79b53b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 7, 2025.

Transparency log

Release files / bilihome-0.1.0-py3-none-any.whl

Download URL bilihome-0.1.0-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d973f977b70064ad8c0b7db14e712d7402eafeb53a1c3a8394c5209e0012f880
BLAKE2b-256 checksum
How to use checksums
f9d1f8f81d9a3440bdce3e751ad951bbff294e19da111bbc785419ee263a6e49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 7, 2025.

Transparency log

Security for BiliHome 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for bilihome-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 7, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page