一个用于获取B站用户信息的Python包
Project description
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来改进这个项目。
支持
如果您在使用过程中遇到问题,请通过以下方式联系:
- 提交Issue: GitHub Issues
- 查看源码: GitHub Repository
版本历史
- v0.1.0 (当前版本)
- 初始版本发布
- 支持获取粉丝数量、关注数量和用户名
注意事项
- 请确保网络连接正常,因为所有数据都通过B站API获取
- 请遵守B站的使用条款和API调用频率限制
- 如果遇到请求失败,请检查网络连接和vmid是否正确
- 本工具仅用于学习和开发目的,请勿用于商业用途
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bilihome-0.1.0.tar.gz.
File metadata
- Download URL: bilihome-0.1.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
452cb371ead54f4904cfb2b0eee44fd63bc5dd1b6baf5a76be6d620339a0c122
|
|
| MD5 |
2f122a23f4e62246dc809b1b9fc982bd
|
|
| BLAKE2b-256 |
fcbd29312374d861331cc63e192c4bb251ef677e0d9aa0b595741a001b79b53b
|
Provenance
The following attestation bundles were made for bilihome-0.1.0.tar.gz:
Publisher:
python-publish.yml on Moxin1044/BiliHome
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bilihome-0.1.0.tar.gz -
Subject digest:
452cb371ead54f4904cfb2b0eee44fd63bc5dd1b6baf5a76be6d620339a0c122 - Sigstore transparency entry: 748063808
- Sigstore integration time:
-
Permalink:
Moxin1044/BiliHome@d443b9e3b81884f814f94ebebd18e2999da8d595 -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/Moxin1044
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@d443b9e3b81884f814f94ebebd18e2999da8d595 -
Trigger Event:
release
-
Statement type:
File details
Details for the file bilihome-0.1.0-py3-none-any.whl.
File metadata
- Download URL: bilihome-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d973f977b70064ad8c0b7db14e712d7402eafeb53a1c3a8394c5209e0012f880
|
|
| MD5 |
885383e828884fea9e928b89155b957e
|
|
| BLAKE2b-256 |
f9d1f8f81d9a3440bdce3e751ad951bbff294e19da111bbc785419ee263a6e49
|
Provenance
The following attestation bundles were made for bilihome-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on Moxin1044/BiliHome
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bilihome-0.1.0-py3-none-any.whl -
Subject digest:
d973f977b70064ad8c0b7db14e712d7402eafeb53a1c3a8394c5209e0012f880 - Sigstore transparency entry: 748063810
- Sigstore integration time:
-
Permalink:
Moxin1044/BiliHome@d443b9e3b81884f814f94ebebd18e2999da8d595 -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/Moxin1044
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@d443b9e3b81884f814f94ebebd18e2999da8d595 -
Trigger Event:
release
-
Statement type: