【自动化】BB自动化获取视频和音频地址并下载

复制代码
from DrissionPage._pages.chromium_page import ChromiumPage
page = ChromiumPage()

page.listen.start('video/BV1qu411b7EY')
page.get('https://www.bilibili.com/video/BV1qu411b7EY/?p=7')
resp = page.listen.wait()
info = resp.response.body
print(info)
headers = {
    'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
    'accept-language': 'zh-CN,zh;q=0.9',
    'cache-control': 'max-age=0',
    # 'cookie': "buvid3=F7CFC4A8-9D7A-09BF-9BA7-3D7F4E3B3D4902388infoc; b_nut=1725671802; b_lsid=1DE87172_191CA0E1005; _uuid=283A2492-C1E2-AC92-2F108-4E1D3C3E79BA04939infoc; CURRENT_FNVAL=4048; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjU5MzEwMDMsImlhdCI6MTcyNTY3MTc0MywicGx0IjotMX0.0-Bn4B3himQ7aN1R09CP-oqQ9MGhISsIgDLII0vnWkg; bili_ticket_expires=1725930943; buvid_fp=2fd96b20892f4ae572daad1cd1ad1f26; buvid4=57818A6E-FEA2-82DD-2303-F7D4AA7381B203733-024090701-XY5a6mPyRvD3DJfqtZUleA%3D%3D; rpdid=|(J|lY)k~Rkl0J'u~klY~u)|l; sid=4rjw28k0",
    'priority': 'u=0, i',
    'sec-ch-ua': '"Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'sec-fetch-dest': 'document',
    'sec-fetch-mode': 'navigate',
    'sec-fetch-site': 'same-origin',
    'sec-fetch-user': '?1',
    'upgrade-insecure-requests': '1',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
}

import json
import requests
# https://api.bilibili.com/x/player/online/total?aid=530457839&cid=1181074835&bvid=BV1qu411b7EY&ts=57522410
# https://www.bilibili.com/video/BV1qu411b7EY?p=
context = json.loads(info)
print(context)
video_url = context['data']['dash']['video'][0]['baseUrl']
audio_url = context['data']['dash']['audio'][0]['baseUrl']
print(video_url,audio_url)

video_re = requests.get(video_url, headers=headers)
audio_re = requests.get(audio_url, headers=headers)

with open("./video.mp4","wb") as f:
    f.write(video_re.content)

with open("./audio.mp4", "wb") as fp:
    fp.write(audio_re.content)
相关推荐
巨大八爪鱼3 分钟前
XP系统下用mod_jk 1.2.40整合apache2.2.16和tomcat 6.0.29,让apache可以同时访问php和jsp页面
java·tomcat·apache·mod_jk
码上一元2 小时前
SpringBoot自动装配原理解析
java·spring boot·后端
计算机-秋大田2 小时前
基于微信小程序的养老院管理系统的设计与实现,LW+源码+讲解
java·spring boot·微信小程序·小程序·vue
小白学大数据3 小时前
Python爬虫开发中的分析与方案制定
开发语言·c++·爬虫·python
魔道不误砍柴功4 小时前
简单叙述 Spring Boot 启动过程
java·数据库·spring boot
Shy9604184 小时前
Doc2Vec句子向量
python·语言模型
失落的香蕉4 小时前
C语言串讲-2之指针和结构体
java·c语言·开发语言
枫叶_v4 小时前
【SpringBoot】22 Txt、Csv文件的读取和写入
java·spring boot·后端
wclass-zhengge4 小时前
SpringCloud篇(配置中心 - Nacos)
java·spring·spring cloud
路在脚下@4 小时前
Springboot 的Servlet Web 应用、响应式 Web 应用(Reactive)以及非 Web 应用(None)的特点和适用场景
java·spring boot·servlet