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.2.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.2-py3-none-any.whl (32.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: weibobot-1.2.2.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.2.tar.gz
Algorithm Hash digest
SHA256 010c5e3e491e7fe104a71730014e3a5645dc86b91cb10ec972c6c1a603e9e5d6
MD5 332fddeadc4bfdd583bde3d30ce16796
BLAKE2b-256 00cfea0d4813de2ccead675b4c908f242aed8588ad9c1eb6705bd867ea76065c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: weibobot-1.2.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f8f4811a4fac4cb90c92c672bf023b05341bcafc7e525f2256bb0e6e0899087b
MD5 2b3f3356c7413b7bb9506952b789aba3
BLAKE2b-256 1793c846487b171627df41279395016687ac1ff04a97250d7b128c8c3e8b6e48

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