獲取B站視頻彈幕,相對來說很簡單,需要用到的知識點有requests、re兩個庫。requests用來獲得網頁信息,re正則匹配獲取你需要的信息,當然還有其他的方法,例如Xpath。
進入你所觀看的視頻的頁面,F12進入開發者工具,選擇網絡。查找我們需要的信息,發現域名那列有comment.bilibili.com 格式為xml ,文件名即為cid號。點擊它后,在右邊的消息頭中復制請求網址,在瀏覽器中打開,即可獲得視頻全部彈幕信息。
代碼如下:

1 import requests 2 import re 3 def getHTML(av): 4 url='https://comment.bilibili.com/'+av+'.xml' 5 html=requests.get(url) 6 comments=html.text 7 res=r'>(.+?)</d>' 8 rescom=re.compile(res) 9 comment=re.findall(rescom,comments) 10 for row in comment: 11 print(row) 12 av=input("input your av:") 13 getHTML(av)
運行代碼,彈幕就全部打印到窗口中,另外關於獲取評論以及用評論內容制作詞雲可查看博客。
原創不易,尊重版權。轉載請注明出處:http://www.cnblogs.com/xsmile/