首页 > 编程语言 >python在B站爬糖豆广场舞

python在B站爬糖豆广场舞

时间:2024-02-22 09:00:37浏览次数:30  
标签:广场 糖豆 get python res url print div ad

先附上代码:

import requests,re
from lxml  import etree

#这是单页面下载,翻页的目前还不会 url = 'https://search.bilibili.com/all?vt=96737335&keyword=%E7%B3%96%E8%B1%86%E5%B9%BF%E5%9C%BA%E8%88%9E' headers = { 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36', 'referer':'https://www.bilibili.com/' } res = requests.get(url,headers=headers) # print(res.text) html = etree.HTML(res.text) links = html.xpath('//*[@id="i_cecream"]/div/div[2]/div[2]/div/div/div/div[2]/div/div[*]/div/div[2]/div/div/a/@href') # print(links) for link in links: link = 'https:'+ link # print(link) url_res = requests.get(link,headers=headers) url_html = etree.HTML(url_res.text) #视频名 title = url_html.xpath('//*[@id="viewbox_report"]/h1/text()')[0] title2 = re.sub('\W','',title) # print(title2) # 获取音频URL get_ad = re.findall(r'"id":30280,"baseUrl":"(.*?)","base_url"',url_res.content.decode()) get_ad2=[] if not get_ad: # print('列表为空') continue else: # print(get_ad[0]) get_ad2 = get_ad # get_ad = re.findall(r'"id":17,"baseUrl":"(.*?)","base_url"',url_res.content.decode()) #获取视频url get_vd = re.findall(r'"id":32,"baseUrl":"(.*?)","base_url"',url_res.content.decode()) get_vd2 = [] if not get_vd: continue else: get_vd2 = get_vd # print(get_vd2) # with open('log2.txt','wb') as f: # f.write(get_vd2) headers2 = { 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36', 'referer':'https://www.bilibili.com', } # 第二次发送请求,请求视频 # print('1111') res_ad = requests.get(get_ad2[0],headers=headers2) res_vd = requests.get(get_vd2[0],headers=headers2) # res2 = res_ad.content print('1111') with open(f'video/{title2}ad.mp4','wb') as f: f.write(res_ad.content) with open(f'video/{title2}vd.mp4','wb') as f: f.write(res_vd.content) print(f'{title2}视频下载完成!') from moviepy.editor import * vd = VideoFileClip(f"video/{title2}vd.mp4") au = AudioFileClip(f"video/{title2}ad.mp4") vd2 = vd.set_audio(au) vd2.write_videofile(f"video/{title2}.mp4")

下载完以后的成果。

 

标签:广场,糖豆,get,python,res,url,print,div,ad
From: https://www.cnblogs.com/davidz/p/18026580

相关文章

  • 1.3 使用pip管理Python扩展库
    常用pip命令使用方法pip命令示例说明pipfreeze[>packages.txt]列出已安装模块及其版本号,可使用重定向符>把扩展库信息保存到文件packages.txt中pipinstallSomePackage[==version]在线安装SomePackage模块,可以使用方括号内的形式指定扩展库版本pipinstallSo......
  • 1.2 Python安装与简单使用
    Python3.6.8安装Python官网:https://www.python.org/Python3.6.8官网:https://www.python.org/downloads/release/python-368/按照提示安装即可,安装完成后,按win+R打开命令行,输入python-V,出现版本号,说明安装成功在开始菜单中选择IDLE(PythonGUI)即可启动Python解释器......
  • 1.1 如何选择Python版本
    简介Python是一门解释型高级语言,支持伪编译可以把Python源程序转换为字节码来优化程序和提高运行速度,支持使用py2exe、py2app、cx_Freeze或pyinstaller工具将Python程序打包为不同平台上的可执行程序,可以在没有安装Python解释器和相关依赖包的系统中运行Python支持多版本并存......
  • Python练习案例_Pico Fermi Bagels猜数字游戏
    案例介绍--《Python编程快速上手2》在PicoFermiBagels这个逻辑推理游戏中,你要根据线索猜出一个三位数。游戏会根据你的猜测给出以下提示之一:如果你猜对一位数字但数字位置不对,则会提示“Pico”;如果你同时猜对了一位数字及其位置,则会提示“Fermi”;如果你猜测的数字及其位置......
  • Python+Faker+Pandas数据库造数
    今日分享一些Python常用的东西,整理一些小笔记,比如Faker的使用,panda的使用1、使用faker造数据简介测试工作中,经常会遇到需要制造大量测试数据的时候,如果手动造数据必然会浪费大量时间Faker是一个制造数据的强大的python库,可以制造姓名、电话、身份证、地址、邮箱等等各种各样伪......
  • Python中logging模块
     在项目中我们常常需要打印日志,特别是在系统级项目上一般都会有自己日志模块,下面我们将介绍下Python中自带的logging模块(注意这是模块的名称并不是类)一、基本使用logging是一个包的名称,我们真正使用的是logging.Logger这个类。但是我们不能使用常规的方式进行初始化,......
  • python-transformers库
    python-transformers库目录python-transformers库安装测试功能和优势Transformers术语模型与分词器加载预训练模型保存模型分词器编码和解码填充Padpipelinepipeline简介pipeline原理参考资料transformers是一个用于自然语言处理(NLP)任务,如文本分类、命名实体识别,机器翻译等,提供......
  • Python:Short Circuiting -- “OR”
    ShortCircuitingOperatorChecksif:Evaluatesfromlefttorightupto:ExampleANDAllvaluesaretrueThefirstfalsevalueFalseand1/0evaluatestoFalseORAtleastonevalueistrueThefirsttruevalueTrueor1/0evaluatestoTrue......
  • python 数据库数据较验
    #-*-coding:utf-8-*-#@Time:2023-09-07#@Author:Carl_DJ"""实现功能:1、python直接链接SqlServer数据库可以MySQL数据库,进行数据对比2、对比mysql和SqlServer两个数据库的表名以及表内数据的差异:3、对比的差异分别输出到文件中---->数据......
  • 【Python&GIS】基于Python融合矢量数据(多面合一)
    ​    之前发过使用批量合并矢量数据的文章:【Python&GIS】基于Python批量合并矢量数据,正好前段时间有需求把矢量数据进行融合,然后就编了一段融合矢量数据的代码。今天就和大家分享一下如何使用Python对矢量数据实现融合的操作。1.定义    首先大家要明白矢量数......