【发布时间】:2021-06-12 13:14:08
【问题描述】:
所以我想从这个链接中提取“bilibili-player-video-info-people-number”: https://www.bilibili.com/video/BV1a44y167wK。当我创建我的 beautifulsoup 对象并搜索它时,这个类不存在。是因为解析器吗?我确实尝试过 lxml 和 html5lib,但都没有更好。
<span class="bilibili-player-video-info-people-number">585</span>
这是我要提取的完整元素 - 数字每分钟更新一次,以显示当前有多少人正在观看。
import time
from bs4 import BeautifulSoup
from selenium import webdriver
import re
import html5lib
driver = webdriver.Chrome(r'C:\Users\Rob\Downloads\chromedriver.exe')
driver.get('https://www.bilibili.com/video/BV1a44y167wK')
content = driver.page_source.encode('utf-8').strip()
soup = BeautifulSoup(content, 'html5lib')
viewers = soup.findAll('span', class_='bilibili-player-video-info-people-text')
print(viewers[0])
print(viewers[0]) 返回一个超出范围的错误,因为查看器对象中没有任何内容。
谢谢!
【问题讨论】:
-
你能检查一下你在
content变量中得到了你期望的东西吗? -
非常感谢这个提示 - 亲爱的托比亚斯。太棒了 - 学习的重要资产!
标签: python web-scraping beautifulsoup