(.+?)
‘, html).group(1)
play_count = re.search(‘(\d+\.?\d*)‘, html).group(1)
danmaku_count = re.search(‘(\d+\.?\d*)‘, html).group(1)
print(f”视频标题:{title}”)
print(f”播放量:{play_count}”)
print(f”弹幕数量:{danmaku_count}”)
# 示例:解析哔哩哔哩视频信息
url = “https://www.bilibili.com/video/BV1GJ411e7h7″
get_video_info(url)
2.2 爬取哔哩哔哩视频排行榜
以下是一个简单的Python脚本,用于爬取哔哩哔哩视频排行榜:
import re
import requests
def get_video_ranking(page):
url = f”https://api.bilibili.com/pgc/season/index/result?seasonversion=1&area=1&isfinish=1&right=1&seasonstatus=1&seasonmonth=1&year=1&styleid=1&order=4&st=1&sort=0&page={page}&seasontype=1&pagesize=20&type=1″
response = requests.get(url)
response.encoding = ‘UTF-8’
json_data = response.json()
for item in json_data[‘data’][‘list’]:
title = item[‘title’]
play_count = item[‘play’]
danmaku_count = item[‘danmaku’]
print(f”标题:{title}”)
print(f”播放量:{play_count}”)
print(f”弹幕数量:{danmaku_count}”)
print(“-” * 20)
# 示例:爬取哔哩哔哩视频排行榜
page = 1
get_video_ranking(page)
三、总结
通过本文的学习,你已掌握了哔哩哔哩正则表达式的入门知识,并学会了如何应用它来解析哔哩哔哩网站数据。这些技能可以帮助你更好地了解哔哩哔哩网站,挖掘有价值的信息,并解锁更多玩法。希望本文能对你有所帮助!