python获取b站某视频弹幕

# -*- coding:utf8 -*-
# -*- author:xiaoxiang -*-

import requests

from bs4 import BeautifulSoup

def get_cid(the_url):
    url = the_url
    response = requests.get(url)
    cid = response.content.decode().split("cid=")[1].split("&aid=")[0]
    return cid

def get_html():
    url = f"https://www.bilibili.com/video/BV1vp4y1a7Ea?p={1}"
    response = get_cid(url)
    the_xml = requests.get(f"https://comment.bilibili.com/{response}.xml")
    soup = BeautifulSoup(the_xml.content, "html.parser")
    all_danmu = soup.find_all("d")
    for i in all_danmu:
        print(i.next_element)

if __name__ == '__main__':
    # print("请输入BV")
    # BV = input()
    # print("请输入p数")
    # end = input()
    get_html()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用Python爬虫获取B站弹幕,可以参考以下步骤: 1. 导入所需的库,如requests和BeautifulSoup。 2. 使用requests库发送HTTP请求来获取B站视频页面的源代码。 3. 使用BeautifulSoup库解析源代码,提取出弹幕相关的信息。 4. 分析B站弹幕的数据结构,例如弹幕内容、发送时间等。 5. 使用Python代码提取出需要的弹幕信息。 6. 可以将获取到的弹幕保存到本地文件或进行进一步的处理和分析。 参考文献提供了更多关于Python爬虫自动化爬取B站实时弹幕的方法和示例代码,可以进一步参考该文献了解更多细节。同时,文献也提供了一个详细的Python爬虫视频弹幕提取过程的示例代码,可以参考该代码实现。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Python爬虫自动化爬取b站实时弹幕实例方法](https://blog.csdn.net/zihong521/article/details/120728886)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* [Python爬虫 视频弹幕提取过程](https://download.csdn.net/download/weixin_42132177/85621862)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值