吃饭放松的时候哇一不小心看见了很多好看的东西
哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈
独乐乐不如众乐乐,
这次就来和大家一起看看~
python 安装包+资料:点击此处跳转文末名片获取
版 本: python 3.8
编辑器: pycharm 2022.3.2 专业版
发送请求 使用代码的方式访问网站
获取数据 取出网页源代码
解析数据 提取shi频链接
保存数据
import requests
import re
import json
import pprint
import subprocess
import os
headers = {
"cookie": "5_1861C3EEC10; theme_style=light; is-2022-channel=1; sid=66dafqju; fingerprint=97ca5a8b555e63aca787c9cd27273c7e; buvid_fp_plain=undefined; buvid_fp=8cc52ae38b592ff26dc2b393eebd890b; PVID=2; innersign=1; bp_video_offset_422789639=758803412994228200",
"referer": "https://小破站要自己打,直接放平台过不了审.com/",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36"
}
url = 'https://****.com/video/BV1qv4y1k7UE/?vd_source=8f216a44bce0dbe14e3447c34c2ab3e2'
1. 发送请求
response = requests.get(url, headers=headers)
2. 获取数据
html_data = response.text
3. 解析数据
# __playinfo__=(.*?)
json_str = re.findall('__playinfo__=(.*?)', html_data)[0]
title = re.findall('(.*?)
', html_data)[0]
json_data = json.loads(json_str)
audio_url = json_data['data']['dash']['audio'][0]['baseUrl']
print(audio_url)
video_url = json_data['data']['dash']['video'][0]['baseUrl']
print(video_url)
4.保存数据
audio_data = requests.get(audio_url, headers=headers).content
with open(f'{title}.mp3', mode='wb') as f:
f.write(audio_data)
video_data = requests.get(video_url, headers=headers).content
with open(f'{title}.mp4', mode='wb') as f:
f.write(video_data)
ffmpeg = f'ffmpeg -i {title}.mp4 -i {title}.mp3 -acodec copy -vcodec copy {title+"-out.mp4"}'
subprocess.run(ffmpeg)
os.remove(f'{title}.mp4')
os.remove(f'{title}.mp3')