获取B站视频弹幕,相对来说很简单,需要用到的知识点有requests、re两个库。requests用来获得网页信息,re正则匹配获取你需要的信息,当然还有其他的方法,例如Xpath。
进入你所观看的视频的页面,F12进入开发者工具,选择网络。查找我们需要的信息,发现域名那列有comment.bilibili.com 格式为xml ,文件名即为cid号。点击它后,在右边的消息头中复制请求网址,在浏览器中打开,即可获得视频全部弹幕信息。

python 爬取B站视频弹幕信息   python 爬取B站视频弹幕信息

代码如下:

 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)
弹幕代码

相关文章:

  • 2022-12-23
  • 2021-05-16
  • 2021-09-26
  • 2021-10-21
  • 2021-11-19
  • 2021-12-03
  • 2021-12-04
猜你喜欢
  • 2021-08-27
  • 2021-11-20
  • 2022-12-23
  • 2021-08-04
  • 2021-09-08
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案