Answer the question
In order to leave comments, you need to log in
How to post a comment on youtube using selenium python?
Here is my code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.select import Select
import os
import os.path
import sys
from time import sleep
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
PATH = os.path.split(os.path.abspath(os.path.realpath(sys.argv[0])))[0] + '/'
options = Options()
options.add_argument("--mute-audio")
#options.add_argument('--headless')
options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36")
driver = webdriver.Chrome(executable_path=PATH + "chromedriver",
options=options)
try:
driver.get('https://www.youtube.com/watch?v=dQw4w9WgXcQ')
#Процес авторизации убрал
sleep(5)
except Exception as ex:
print(ex)
finally:
driver.close()
driver.quit()
Message:
Answer the question
In order to leave comments, you need to log in
Add lines:
#Activate the box
commentBox = driver.find_element_by_id('placeholder-area')
commentBox.click()
sleep(4)
#Send the keys to the input field
inputBox =driver.find_element_by_id('contenteditable-root')
inputBox.send_keys('test')
You need to search for an object, by class or tag, or id, etc.
Then peped value to this object.
Well, register a button press.
variable_name = find_element_by_id
#_by_class_name
#_by_tag_name
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question