下载b站视频高清封面

# 下载b站视频高清封面
import requests
from bs4 import BeautifulSoup
import re

if __name__ == '__main__':

url = ''
while True:
user_input = input("粘贴B站视频链接然后回车:")
if "bilibili.com/video/BV" in user_input:
url = user_input
break
else:
print("输入无效,请重新输入")

headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
}
response = requests.get(url=url, headers=headers)
soup = BeautifulSoup(response.text, "lxml")
a = soup.find("meta", {"itemprop": "image"})
b = re.sub(r'@.*', '', a['content'])
c = 'https:'+b
r = requests.get(c).content
with open(c.split("/")[-1], 'wb') as f:
f.write(r)
print('图片下载完成')
input('按回车键退出')

下载地址

https://www.123pan.com/s/QZGSVv-6ZqN3.html