url
=
"https://www.bilibili.com/video/BV1Xy4y1y7eU"
response
= requests.get(url)
html_content
= response.text
使用 BeautifulSoup 库解析 HTML 内容,获取视频标题和播放量
from bs4 import BeautifulSoup
soup = BeautifulSoup(html_content, 'html.parser')
title = soup.find('h1', class_='video-title').text.strip()
views = soup.find('span', class_='view').text.strip()
完整代码:
import requests
from bs4 import BeautifulSoup
url = "https://www.bilibili.com/video/BV1Xy4y1y7eU"
response = requests.get(url)
html_content = response.text
soup = BeautifulSoup(html_content, 'html.parser')
title = soup.find('h1', class_='video-title').text.strip()
views = soup.find('span', class_='view').text.strip()
print('视频标题:', title)
print('播放量:', views)
输出结果:
视频标题: 【全程】2021年Xiao Zhan'全球限定生日会'在线直播完整版vivo刘海屏旁边的他X王琳凯
播放量: 3,017.8万
Mintimate
Python
数据可视化
- 268
-
NicesLife
Python
Selenium