15行python程式碼實時獲取鬥魚彈幕
阿新 • • 發佈:2019-02-14
演示效果截圖
程式碼如下
import time, sys, danmu
def pp(msg):
print(msg.encode(sys.stdin.encoding, 'ignore').decode(sys.stdin.encoding))
dmc = danmu.DanMuClient('https://www.douyu.com/1888275')
if not dmc.isValid(): print('Url not valid')
@dmc.danmu
def danmu_fn(msg):
pp('[%s] %s' % (msg['NickName'], msg['Content' ]))
@dmc.gift
def gift_fn(msg):
pp('[%s] sent a gift!' % msg['NickName'])
@dmc.other
def other_fn(msg):
pp('Other message received')
dmc.start(blockThread = True)