Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python我无法在youtube上发表评论_Python_Selenium_Selenium Webdriver - Fatal编程技术网

Python我无法在youtube上发表评论

Python我无法在youtube上发表评论,python,selenium,selenium-webdriver,Python,Selenium,Selenium Webdriver,我正试图在youtube视频上发表评论。 当我运行脚本时,我得到一个错误 请帮我纠正这个错误 from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from se

我正试图在youtube视频上发表评论。 当我运行脚本时,我得到一个错误 请帮我纠正这个错误

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys


chrome_path = r"xxxxxxxx"
chrome_options = webdriver.ChromeOptions()
driver = webdriver.Chrome(chrome_path,chrome_options=chrome_options)
driver.get('https://accounts.google.com/ServiceLogin?continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Fhl%3Den%26feature%3Dcomment%26app%3Ddesktop%26next%3D%252Fall_comments%253Fv%253DKdsJtbecX_A%26action_handle_signin%3Dtrue&uilel=3&service=youtube&passive=true&hl=en')

# post a comment
comment = "test"

box = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CLASS_NAME, "box")))
box.click()

frame = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, '//iframe[@title="+1"]')))
driver.switch_to.frame(frame)

driver.find_element_by_xpath('//div[@onclick]').click()

element = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, '//div[@jsname="msEQQc"]/following-sibling::div//div[@g_editable="true"]')))
driver.execute_script("arguments[0].innerHTML='%s';" % comment, element)
这是一个错误

  File "yt.py", line 17, in <module>
    box = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CLASS_NAME, "box")))
  File "C:\Python3\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
文件“yt.py”,第17行,在
box=WebDriverWait(驱动程序,20)。直到(EC.元素的存在位置((By.CLASS\u名称,“box”))
文件“C:\Python3\lib\site packages\selenium\webdriver\support\wait.py”,第80行,直到
引发TimeoutException(消息、屏幕、堆栈跟踪)
selenium.common.Exception.TimeoutException:消息:
在此步骤中

驱动程序。获取(“”)

您正在导航到youtube的登录页面

如果未完成登录过程,则无法找到元素


请注意,selenium在打开浏览器时会显示一个干净的图标(没有coockies、cache…)

我知道。登录后,我才试图找到。