import requests import xml.etree.ElementTree as ET def get_danmaku(video_id): url = "https://api.bilibili.com/x/v1/dm/list.so?oid={}".format(video_id) response = requests.get(url) if response.status_code == 200: root = ET.fromstring(response.content) danmaku_list = [] for d in root.findall('d'): text = d.text if text: danmaku_list.append(text) return danmaku_list return []