python项目源码解析1:blivedm

python项目源码解析1:blivedm

源码:blivedm

Python获取bilibili直播弹幕的库,使用WebSocket协议,支持web端和B站直播开放平台两种接

本文能帮助 解决 一个问题

alt

SESSDATA 是 B站 的登陆凭证,每个账户登录后都会在服务器生成一个单独的 SESSDATA, 如果不刷新有效期为半个月。

可以用 SESSDATA 来请求某些必须要登录状态才能访问的 A

  • chrome浏览器打开bilibili 并登录

  • f12

  • 点开下拉菜单依次选择application -> cookies -> www.bilibili.com

  • storage alt

  • cookeis

alt

剩余是代码学习

def set_handler(self, handler: Optional['handlers.HandlerInterface']):
        """
        设置消息处理器

        注意消息处理器和网络协程运行在同一个协程,如果处理消息耗时太长会阻塞接收消息。如果是CPU密集型的任务,建议将消息推到线程池处理;
        
        如果是IO密集型的任务,应该使用async函数,并且在handler里使用create_task创建新的协程

        :param handler: 消息处理器
        "
""
        self._handler = handler

pyhon Optional

typing.Optional 可选类型

Optional[X]等价于 Union[X, None]

How to Run an Asyncio Program in Python

  • asyncio is a library to write concurrent code using the async/await syntax.

asyncio is used as a foundation for multiple Python asynchronous frameworks that provide high-performance network and web-servers, database connection libraries, distributed task queues, etc.

asyncio is often a perfect fit for IO-bound and high-level structured network code.

  • The run() function will start the asyncio event loop and will schedule the coroutine provided as an argument. This function runs the passed coroutine, taking care of managing the asyncio event loop, finalizing asynchronous generators, and closing the threadpool.
# SuperFastPython.com
# example of starting an asyncio program
import asyncio
 
# custom coroutine
async def custom_coro(message):
    # report the message
    print(message)
 
# create and execute coroutine
asyncio.run(custom_coro('hello world'))

alt 更多咨询

本文由 mdnice 多平台发布

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值