如何从网站上找到 Python 的按钮 ID?
How do I find out the Button ID from a Website for Python?
我正在尝试使用 Python 创建一个文件,让我可以一键启动 YouTube 流媒体。我为此使用 pythons webbrowser。但是要按下按钮,我需要知道开始按钮的 ID。不幸的是,我对浏览器中的检查器并不十分了解。
我希望你能帮我解决这个问题。
乔纳斯
import webbrowser
url = "https://studio.youtube.com/channel/........./livestreaming/stream"
chrome_url = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s"
browser = webbrowser.get(chrome_url)
browser.open(url)
button = browser.find_element_by_id(button_id)
button.click()
Youtube Inspector Image
在 python 中,您可以尝试使用 Selenium 实现相同的目的,相同的代码是:
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver.chrome.options import Options
chrome_options = webdriver.ChromeOptions()
driver = webdriver.Chrome(chrome_options=chrome_options,executable_path="C://downloads//chromedriver.exe")
driver.get("url for the youtube video")
sleep(2)
element=driver.find_element_by_xpath("//*[@class='ytp-large-play-button ytp-button']")
element.click()
我正在尝试使用 Python 创建一个文件,让我可以一键启动 YouTube 流媒体。我为此使用 pythons webbrowser。但是要按下按钮,我需要知道开始按钮的 ID。不幸的是,我对浏览器中的检查器并不十分了解。 我希望你能帮我解决这个问题。 乔纳斯
import webbrowser
url = "https://studio.youtube.com/channel/........./livestreaming/stream"
chrome_url = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s"
browser = webbrowser.get(chrome_url)
browser.open(url)
button = browser.find_element_by_id(button_id)
button.click()
Youtube Inspector Image
在 python 中,您可以尝试使用 Selenium 实现相同的目的,相同的代码是:
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver.chrome.options import Options
chrome_options = webdriver.ChromeOptions()
driver = webdriver.Chrome(chrome_options=chrome_options,executable_path="C://downloads//chromedriver.exe")
driver.get("url for the youtube video")
sleep(2)
element=driver.find_element_by_xpath("//*[@class='ytp-large-play-button ytp-button']")
element.click()