WeiboBot 是一个基于微博H5 API开发的爬虫框架,提供了简单的接口,包括了一些指令,比如:转评赞,回复消息等 可以选择直接获取数据,也可以持续运行
安装
普通安装
pip install WeiboBot
带截图功能
pip install WeiboBot[screenshot]
源码安装(推荐使用uv)
uv sync --all-extras
开始使用(生命周期)
from loguru import logger
from WeiboBot import Bot, ChatDetail, Comment, Weibo
bot = Bot()
@bot.onNewMsg() # 被私信的时候触发
async def on_msg(chat: ChatDetail):
for msg in chat.msgs: # 消息列表
logger.info(f"{msg.sender_screen_name}:{msg.text}")
@bot.onNewWeibo() # 首页刷到新微博时触发
async def on_weibo(weibo: Weibo):
weibo = await bot.weibo_info(weibo.mid) # 获取微博详细信息(长微博才需要)
logger.info(f"{weibo.text}")
@bot.onMentionCmt() # 提及我的评论时触发
async def on_mention_cmt(cmt: Comment):
logger.info(f"收到{cmt.mid}的评论")
@bot.onTick() # 每次循环触发
async def on_tick():
logger.info("tick")
if __name__ == "__main__":
bot.run()
开始使用(仅调用)
import asyncio
from loguru import logger
import WeiboBot.const as const
from WeiboBot import NetTool
async def main():
async with NetTool() as nettool:
user = await nettool.user_info(nettool.mid)
logger.info(user)
weibo_example1 = await nettool.weibo_info(123456) # 获取微博
weibo_example2 = await nettool.post_weibo(
"发一条微博", visible=const.VISIBLE.ONLY_ME
)
# ...... 其他操作
if __name__ == "__main__":
asyncio.run(main())
更新路线图
目前项目仍在重构中
- 对旧API的整合
- 扩展更加多的API
- 提升登录的健壮性
- 增加更多测试用例和自动化
- 去掉 logger
示例
正在重构中
一个转发小姐姐的Bot
Metadata
Release files for WeiboBot 1.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| weibobot-1.2.3.tar.gz | 29.2 kB | Without provenance | Details for weibobot-1.2.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| weibobot-1.2.3-py3-none-any.whl | Python 3 | none | any | Details for weibobot-1.2.3-py3-none-any.whl |
Total release size: 61.9 kB
Release files / weibobot-1.2.3.tar.gz
| Download URL | weibobot-1.2.3.tar.gz |
|---|---|
| Size | 29.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7b3d158d6eccbed9844d5a4a96a2f9315cf9c56e5c7e64f18d4d32afd2e17432
|
|
BLAKE2b-256 checksum How to use checksums |
e1b3912aa4cc62c74db156fab6cff5b4d4506742fdb3e9f4274c025fabb8fdd8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.13
|
Release files / weibobot-1.2.3-py3-none-any.whl
| Download URL | weibobot-1.2.3-py3-none-any.whl |
|---|---|
| Size | 32.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0e70d8e604f6642e7618a5e975f2af2df21fe767118af28d5d0f0229a124dab1
|
|
BLAKE2b-256 checksum How to use checksums |
b4a329a18c362ab290a93fc5db72db364206a6da4d824018c8afed914ca930ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.13
|
Security for WeiboBot 1.2.3
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.