from selenium import webdriver
from selenium.webdriver.common.by import By
#不让浏览器自动关闭
options = webdriver.EdgeOptions()
options.add_experimental_option('detach', True)
driver = webdriver.ChromiumEdge(options=options)
#加载网页,获取源代码
url = 'https://www.bilibili.com/v/popular/all/'
driver.get(url)
#导入BeautifulSoup,筛选数据
from bs4 import BeautifulSoup
soup = BeautifulSoup(driver.page_source, 'lxml')
result = soup.find_all('div', class_='video-card')
for item in result:
title = item.find('p', class_='video-name')
up = item.find('span', class_='up-name__text')
count = item.find('span', class_='play-text')
print(f'视频:{title.text},UP:{up.text},播放量:{count.text.strip()}')
考试自用代码2
最新推荐文章于 2024-09-11 11:22:05 发布