import requests
import re
import you_get
import sys
video_name = input('请输入你想要看的内容:')
page = input('你想观赏第几页:')
url = 'https://search.bilibili.com/video?keyword={}&page={}'.format(video_name, page)
path = 'E:/哔哩哔哩小视频' # 视频保存的路径
response = requests.get(url).content.decode('utf-8') # 获得页面内容
# print(response)
video_url = re.findall('a href="//www.bilibili.com/video/(.*?)?from=search', response) # 抓取每页所有视频的播放地址
video_names = re.findall('<a title="(.*?)"', response) # 抓取每页所有视频的名字
urls = []
# for i in video_names:
# print(i)
j = 0
for i in video_url:
urls.append('https://www.bilibili.com/video/' + i[:-1]) # 拼接小视频完整的播放地址
for i in video_names:
print('%d:' % (j + 1) + i, sep="", end=" ")
print('观看地址:' + urls[j])
j += 1
video_num = int(input('你想下载第几个视频:'))
sys.argv = ['you-get', '-o', path, urls[video_num-1]]
you_get.main()
print('下载成功!')
python实战-B站视屏
最新推荐文章于 2023-12-20 16:30:28 发布