【问题标题】:how to incease sleep time of selenium until song complete如何增加硒的睡眠时间直到歌曲完成
【发布时间】:2021-10-04 07:06:09
【问题描述】:

我怎样才能将这个睡眠时间增加到我的歌曲完成为止。我正在开发语音助手。

def play(self,query):
            self.query=query
            self.driver.get(url="https://www.youtube.com/results?search_query=" + query)
            video=self.driver.find_element_by_xpath('//*[@id="video-title"]/yt-formatted-string')
            video.click()
            time.sleep(50)

【问题讨论】:

  • 我的回答解决了你的问题吗?

标签: python selenium


【解决方案1】:

建议将睡眠持续时间设置为您可以使用this检索的视频持续时间

【讨论】:

    【解决方案2】:

    当单个 YouTube 视频播放完毕时,Play Next 和 Cancel 按钮出现。
    因此,您可以使用预期条件等到该元素出现。像这样:

    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    wait = WebDriverWait(driver, 20000)
    
    wait.until(EC.visibility_of_element_located((By.XPATH, "//a[@class='ytp-autonav-endscreen-upnext-button ytp-autonav-endscreen-upnext-play-button']")))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-30
      • 2017-07-25
      相关资源
      最近更新 更多