from selenium import webdriver
import time
from selenium.webdriver.common.action_chains import ActionChains
driver =webdriver.Chrome()
driver.get("https://www.huya.com/20348224")
login_btn = driver.find_element_by_id("nav-login")
login_btn.click()
time.sleep(2)
driver.switch_to.frame("UDBSdkLgn_iframe") #切换到登录框里面
driver.find_element_by_xpath("//*[@id=\"account-login-form\"]//div[1]/input").send_keys("xxxxx")
driver.find_element_by_xpath("//*[@id=\"account-login-form\"]//div[2]/input").send_keys("xxxxx")
btn = driver.find_element_by_id("login-btn")
btn.click()
time.sleep(3)#模拟登录
driver.switch_to.default_content()#切换出来
element = driver.find_element_by_id("player-video")
ActionChains(driver).move_to_element(element).perform()#将鼠标悬停,不然有些元素隐藏了
time.sleep(1)
driver.find_element_by_xpath("//*[@id=\"player-fullscreen-btn\"]").click()#网页版只能全屏发弹幕,故这里切换为全屏
driver.find_element_by_id("player-full-input-txt").send_keys("hello")#输入发送的弹幕
time.sleep(1)
driver.find_element_by_id("player-full-input-btn").click()
time.sleep(20)
driver.close()
使用selenium发送弹幕(虎牙)
最新推荐文章于 2022-04-10 22:04:53 发布