import requests
import os
import subprocess
url = ‘https://api.bilibili.com/x/space/wbi/arc/search?mid=3493140394674396&pn=1&ps=25&index=1&order=pubdate&order_avoided=true&platform=web&web_location=1550101&dm_img_list=[]&dm_img_str=V2ViR0wgMS4wIChPcGVuR0wgRVMgMi4wIENocm9taXVtKQ&dm_cover_img_str=QU5HTEUgKEludGVsLCBNb2JpbGUgSW50ZWwoUikgNCBTZXJpZXMgRXhwcmVzcyBDaGlwc2V0IEZhbWlseSAoTWljcm9zb2Z0IENvcnBvcmF0aW9uIC0gV0RETSAxLjEpIERpcmVjdDNEOUV4IHZzXzNfMCBwc18zXzAsIGlnZHVtZDY0LmRsbClHb29nbGUgSW5jLiAoSW50ZW&dm_img_inter=%7B%22ds%22:[%7B%22t%22:2,%22c%22:%22Y2xlYXJmaXggZy1zZWFyY2ggc2VhcmNoLWNvbnRhaW5lcg%22,%22p%22:[229,7,-2262],%22s%22:[126,588,668]%7D,%7B%22t%22:2,%22c%22:%22c2VjdGlvbiB2aWRlbyBsb2FkaW5nIGZ1bGwtcm93cw%22,%22p%22:[-530,50,-1410],%22s%22:[242,2982,2004]%7D],%22wh%22:[2013,1121,59],%22of%22:[426,852,426]%7D&w_webid=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzcG1faWQiOiIzMzMuOTk5IiwiYnV2aWQiOiI0Rjg2MUFFQi01OTA2LTgxQTYtNkU0RC0wRjMwOUVEMTkwMEM4NzU3MGluZm9jIiwidXNlcl9hZ2VudCI6Ik1vemlsbGEvNS4wIChXaW5kb3dzIE5UIDEwLjA7IFdpbjY0OyB4NjQpIEFwcGxlV2ViS2l0LzUzNy4zNiAoS0hUTUwsIGxpa2UgR2Vja28pIENocm9tZS8xMzEuMC4wLjAgU2FmYXJpLzUzNy4zNiBFZGcvMTMxLjAuMC4wIiwiYnV2aWRfZnAiOiIxNGI5NDI2YTJmZGYxNTEwMTVlYmU3MTk0YTFkYjM0YyIsImJpbGlfdGlja2V0IjoiZXlKaGJHY2lPaUpJVXpJMU5pSXNJbXRwWkNJNkluTXdNeUlzSW5SNWNDSTZJa3BYVkNKOS5leUpsZUhBaU9qRTNNelk1TWprM05Ea3NJbWxoZENJNk1UY3pOalkzTURRNE9Td2ljR3gwSWpvdE1YMC5hTzVhRXp4Ri1VeXlIaHM2X3FxRWZjekM5NkVhYVJSYmtwa2txVndmSGhnIiwiY3JlYXRlZF9hdCI6MTczNjY3MDcwMCwidHRsIjo4NjQwMCwidXJsIjoiLzM0OTMxNDAzOTQ2NzQzOTYiLCJyZXN1bHQiOjAsImlzcyI6ImdhaWEiLCJpYXQiOjE3MzY2NzA3MDB9.QeySbAYzMBgnFhLF8wqaxlWS1cuKvMpL5HUTsLPLCf6KVsXAttnZV1S5w8xo_0Pxy3CX3o4ACPKbe32tFLx6jWjLYG1snKsUCdWcJGr7jhRjCB3FIyKgZmUreiad-_Yw7ug-a6pDzPprGLMRsSKneIX_u1eHELvyhyzfoRUWrnfQi4e26UalSIJQKkT9c4-gk1jRKTNjSeyX2BNpVVeFz3LFQRq6MGdXfAn2PvpPyZrO4hxjU4iTBDdxkzWAAnyP-CxzqJjNR0hfXn0e0CgjCoMRbl28qTRpXXtO7EI04c8UPuujpIEouuV_u5HTLiI6lmaJJFEVN1Aas5I-8XDi7w&w_rid=893911c29e36515b0f688658904a89ad&wts=1736670723’
headers = {
‘user-agent’: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0’,
‘referer’: ‘https://space.bilibili.com/3493140394674396’
}
response = requests.get(url=url, headers=headers).json()
if not os.path.exists(‘./mv’):
os.mkdir(‘./mv’)
for video_info in response[‘data’][‘list’][‘vlist’]:
title = video_info[‘title’]
video_url = ‘https://www.bilibili.com/video/’ + video_info[‘bvid’] + ‘/?spm_id_from=333.999.0.0’
def download_bilibili_video(video_url):
try:
# 使用you-get下载视频,-o指定输出目录(这里是当前目录)
subprocess.run([‘you-get’, ‘-o’, ‘./mv’, video_url], check=True) # 修改输出目录为./mv,更符合前面创建目录的意图
print(“视频下载成功!”)
except subprocess.CalledProcessError as e:
print(“下载过程中出现错误:”, e)
if __name__ == "__main__":
download_bilibili_video(video_url)
标签:__,img,22,python,daifanyedeshipin,bilibili,url,video,程序代码 From: https://blog.csdn.net/qq_32257509/article/details/145097749