【问题标题】:Automating Opening Transcript for Youtube Automatic Generated Captions为 Youtube 自动生成的字幕自动打开脚本
【发布时间】:2018-12-03 11:34:13
【问题描述】:

我正在尝试编写一个 python 脚本,该脚本将自动单击打开 youtube 视频的脚本。

例如,如果您访问 youtube 视频,在分享按钮右侧的两个(由 3 个点表示),您可以打开 youtube 视频的脚本。

到目前为止,我的代码打开了 URL,并打开了隐藏式字幕(有效)。

from selenium import webdriver
import requests

driver = webdriver.Chrome()
driver.get("https://www.youtube.com/watch?v=q1RYI034sH0")
element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, "ytp-subtitles-button")))
element.click()

但是,我知道要通过添加以下代码来打开脚本,这会产生错误,因为它找不到按钮。

element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, "yt-icon-button)")))

我不太确定从这里做什么,非常感谢自动打开 youtube 成绩单的任何帮助。

【问题讨论】:

    标签: python selenium youtube automation


    【解决方案1】:

    试试这个代码:

    # opens 'More actions' menu
    more_action_btn = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[@aria-label = 'More actions']")))
    more_action_btn.click()
    
    # clicks on 'open transcription' button    
    open_trancript_btn = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//paper-listbox[@id = 'items']/ytd-menu-service-item-renderer")))
    open_trancript_btn.click() 
    

    【讨论】:

    • 第一个动作完美运行,它点击了更多动作按钮(谢谢!)。但是,第二个命令会给出错误“Timeout.Exception”,因为 Xpath 不正确。有什么想法吗?
    • 对不起,我在第二个元素上做错了,请检查更新后的答案
    • 试图完成这项工作。似乎坏了:文件“scrape-videos-for-stations.py”,第 32 行,在 get_transcript more_action_btn = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[@aria -label = '更多操作']"))) 文件“C:\Users\Roman Davis\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\support\wait.py” ,第 80 行,直到引发 TimeoutException(message, screen, stacktrace)
    猜你喜欢
    • 1970-01-01
    • 2017-08-12
    • 2021-12-01
    • 2018-08-25
    • 2019-04-23
    • 1970-01-01
    • 2020-03-12
    • 2017-03-20
    • 2015-02-01
    相关资源
    最近更新 更多