gpt4 book ai didi

python - 为 Youtube 自动生成的字幕自动打开脚本

转载 作者:太空宇宙 更新时间:2023-11-04 04:39:18 24 4
gpt4 key购买 nike

我正在尝试编写一个 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 的成绩单。

最佳答案

试试这段代码:

# 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()

关于python - 为 Youtube 自动生成的字幕自动打开脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51014205/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com