Skip to main content

基于微博H5 API开发的机器人框架

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

weibobot-1.2.1.tar.gz (29.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

weibobot-1.2.1-py3-none-any.whl (32.7 kB view details)

Uploaded Python 3

File details

Details for the file weibobot-1.2.1.tar.gz.

File metadata

  • Download URL: weibobot-1.2.1.tar.gz
  • Upload date:
  • Size: 29.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.13

File hashes

Hashes for weibobot-1.2.1.tar.gz
Algorithm Hash digest
SHA256 772c4831ab9d781338424fc885b55ecfccdc93392c8e591e6c0fe465465c6f9a
MD5 88c17e5425a0517def58a516c3cd31c1
BLAKE2b-256 5a7df83729fe1a9936dae7f8a9ae8920397d7de18ca337cda0d712be67eae9b0

See more details on using hashes here.

File details

Details for the file weibobot-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: weibobot-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 32.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.13

File hashes

Hashes for weibobot-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a967ba02b2684493e5263869a4ca219664f75d5dc42254f25948cc6a14ebbe0c
MD5 33348c39303c0f08666878e87207bca1
BLAKE2b-256 dbf48f7cefc502df10ea71debd2c40689954975281a740dda454b19032f1426c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page