我正式需要帮助。
下面是使用selenium .find_element方法登录管道的完整代码
导航到特定的视频,向下滚动并尝试选择一个youtube评论框。我已经尝试过所有selenium方法找到一个注释框并单击它(我不会列出所有这些),但没有成功。
谁能告诉我什么可能出了问题吗。考虑到我已经成功地使用selenium方法登录到you管道,我看不出为什么同样的方法不适用于查找您的管道评论框。
import time
import numpy as np
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
from selenium.common.exceptions import NoSuchElementException
def youtube_login():
email = 'email@gmail.com'
password = 'password'
comment = 'We are looking for good people/traders like yourself to join a new trading chatroom. Chatroom has a multi asset live squawk news, economic events notifications and soon live trade callouts and trade stream. For now the main focus is bond futures but all asset classes are welcome. If you are interested please join while its still free https://discord.gg/ssDvDnx?'
# Browser
driver = webdriver.Firefox()
driver.get('https://accounts.google.com/ServiceLogin?hl=en&continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Fhl%3Den%26feature%3Dsign_in_button%26app%3Ddesktop%26action_handle_signin%3Dtrue%26next%3D%252F&uilel=3&passive=true&service=youtube#identifier')
#driver.maximize_window()
# log in
driver.find_element_by_id('identifierId').send_keys(email)
driver.find_element_by_class_name('CwaK9').click()
WebDriverWait(driver, 500).until(EC.element_to_be_clickable((By.NAME, "password")))
driver.find_element_by_name('password').send_keys(password)
WebDriverWait(driver, 500).until(EC.element_to_be_clickable((By.CLASS_NAME, "CwaK9")))
driver.find_element_by_class_name('CwaK9').click()
WebDriverWait(driver, 500).until(EC.element_to_be_clickable((By.ID, "identity-prompt-confirm-button")))
driver.find_element_by_id('identity-prompt-confirm-button').click()
urls = []
# You can add in a file and import from there
inp = open ("urls.txt","r")
for line in inp.readlines():
urls.append(line.strip())
inp.close()
for url in urls:
driver.get(url)
time.sleep(5)
# Scroll, wait for load comment box
driver.execute_script("window.scrollTo(0, 500);")
# Lets wait for comment box
box = WebDriverWait(driver, 15).until(EC.presence_of_element_located((By.ID, "emoji")))
# Activate box for comments
box.click()
driver.implicitly_wait(5)
driver.find_element_by_id("emoji").send_keys(comment)
youtube_login()发布于 2018-10-28 17:47:21
要触发注释框,请单击id 'placeholder-area‘的元素,然后将出现表情符号输入。
之后,使用id 'contenteditable-textarea‘到sendKeys的输入(’注释文本‘),如果这不能从驱动程序发送可执行脚本:
document.getElementById('contenteditable-textarea').innerHTML =“您的评论文本在这里”
发布于 2020-03-31 15:16:19
添加这一行
#Activate the box
commentBox = driver.find_element_by_id('placeholder-area')
commentBox.click()
time.sleep(4)
#Send the keys to the input field
inputBox =driver.find_element_by_id('contenteditable-root')
inputBox.send_keys('test')它在2020年为我工作:)
发布于 2020-09-12 16:34:59
这可能有点晚了,但为什么你不直接进入像这样的随机视频:
while True:
try:
recently = chrome_browser.find_element_by_xpath('//yt-formatted-string[@title="Recently uploaded"]')
recently.click()
break
except:
continue
time.sleep(10)
video = chrome_browser.find_element_by_xpath('//div[@class="style-scope ytd-rich-item-renderer"]')
video.click()https://stackoverflow.com/questions/53032772
复制相似问题