"""爬取实时的虎牙弹幕"""
"""不出现重复弹幕"""
"""不遗漏弹幕"""
from selenium import webdriver
import time
web = webdriver.Chrome()
web.get('https://www.huya.com/52333')
"""第一版"""
# while True:
# bullets_chat = web.find_elements_by_xpath('//*[@id="chat-room__list"]/div/div/span[3]')
# for bullet in bullets_chat:
# if bullet.text:
# print(bullet.text)
# time.sleep(3)
# 缺点:会出现重复弹幕,为减少重复弹幕增加sleep时间会遗漏弹幕
"""第二版"""
# bbb = []
# while True:
# bullets_chat = web.find_elements_by_class_name('msg')
# for bullet in bullets_chat:
# if bullet.text and bullet.text not in bbb:
# print(bullet.text)
# bbb.append(bullet.text)
# time.sleep(0.5)
# 缺点 1.bbb列表会越来越大,拖慢内存 2.如果两个人发了两个相同弹幕比如哈哈哈,只会出现1个
"""第三版"""
# bbb = []
# while True:
# bullets_chat = web.find_elements_by_class_name('msg')
# for bullet in bullets_chat:
# if bullet.text and bullet.text not in bbb:
#
huya弹幕提取小尝试
最新推荐文章于 2026-06-20 21:17:12 发布


4518

被折叠的 条评论
为什么被折叠?



