diff --git a/2.py b/2.py new file mode 100644 index 0000000..d523fcd --- /dev/null +++ b/2.py @@ -0,0 +1,16 @@ +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 []