使用
将代码中的url换成视频的链接
运行代码就能把封面地址打印出来,浏览器打开就能查看
代码
# @Time : 2020/10/28 17:59
# @Author : zym
# @File : bilibili.py
# @Software: PyCharm
import requests
import bs4
header = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36 Edg/86.0.622.51"}
url = "https://www.bilibili.com/video/av170001"
def main():
res = requests.get(url, headers=header)
res.encoding = res.apparent_encoding
soups = bs4.BeautifulSoup(res.text, "html.parser")
target = soups.find("meta", itemprop="thumbnailUrl")
print(target["content"])
if __name__ == '__main__':
main()