Skip to main content

WeiboBot

基于微博H5 API开发的爬虫框架

PyPI Python Version Python Implementation

License

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

正在重构中

一个转发小姐姐的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)

Source distribution for WeiboBot 1.2.3
File Size Uploaded
weibobot-1.2.3.tar.gz 29.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for WeiboBot 1.2.3
File Interpreter ABI Platform
weibobot-1.2.3-py3-none-any.whl Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

1.2.3 This release

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.4.5

1 release file

0.3.7

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.1

1 release file

0.1.9

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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