生成代码python3爬取b站热门视频
时间: 2023-09-30 16:09:51 浏览: 45
好的,以下是可以使用的Python 3代码,可以爬取B站热门视频:
```python
import requests
from bs4 import BeautifulSoup
url = 'https://www.bilibili.com/v/popular/rank/all'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
videos = soup.find_all('li', class_='rank-item')
for video in videos:
title = video.find('a', class_='title').text.strip()
link = 'https:' + video.find('a', class_='title')['href']
play_count = video.find('span', class_='data-box').text.strip()
print('标题:', title)
print('链接:', link)
print('播放量:', play_count)
print('-----------------------')
```
这个代码使用了 requests 库来发送 HTTP 请求,并使用了 BeautifulSoup 库来解析 HTML 页面。它会从 B 站热门排行榜页面中获取视频的标题、链接和播放量,并将这些信息打印到控制台中。