diff --git a/爬取视频.py b/爬取视频.py new file mode 100644 index 0000000..54e0be8 --- /dev/null +++ b/爬取视频.py @@ -0,0 +1,43 @@ +import os +import requests + +url='https://www.bilibili.com/video/BV1jm4y167fE' + +headers={ + 'referer': 'https://www.bilibili.com/video/BV1jm4y167fE/?vd_source=59fecc30e7f4791084968599ca1f8b82', + 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36' +} +response=requests.get(url=url,headers=headers) + +import re + +title=re.findall('

',response.text)[0] +playinfo=re.findall('',response.text)[0] + +import json +json_data=json.loads(playinfo) + +import pprint + +audio_url=json_data['data']['dash']['audio'][0]['baseUrl'] +video_url=json_data['data']['dash']['video'][0]['baseUrl'] +# pprint.pprint(json_data) + +audio_content=requests.get(url=audio_url,headers=headers).content +vedio_content=requests.get(url=video_url,headers=headers).content + +with open('vedio\\'+title+'.mp3',mode='wb') as f: + f.write(audio_content) +with open('vedio\\' + title + '.mp4', mode='wb') as f: + f.write(vedio_content) + +# video_path = 'D:\python爬虫学习\爬取b站\\vedio\\' + title + '.mp4' +# audio_path = 'D:\python爬虫学习\爬取b站\\vedio\\'+title+'.mp3' +# output_path = 'D:\python爬虫学习\爬取b站\\vedio\\'+'mixer.mp3' +# +# os.system(f'ffmpeg -i {video_path} -i {audio_path} -c:v copy -c:a copy -bsf:a aac_adtstoasc {output_path}') + +import subprocess + +COMMAND = f'ffmpeg -i vedio\\{title}.mp4 -i vedio\\{title}.mp3 -c:v copy -c:a aac -strict experimental vedio\\{title}output.mp4' +subprocess.run(COMMAND,shell=True)