我使用以下代码在YouTube上添加评论,但当我添加评论时,它在刷新页面后不会出现。 但当我在个人浏览器中发表评论时,评论会正常显示 我想谷歌知道我使用的是非个人浏览器,所以不会显示评论 有解决这个问题的办法吗
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.action_chains import ActionChains
from selenium_stealth import stealth
import time
import os
import pickle
urlVideo = str(input('Enter your URL video: '))
import io
with io.open('message.txt', "r", encoding="utf-8") as f:
message = f.readlines()
options = webdriver.ChromeOptions()
options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument('--disable-blink-features=AutomationControlled')
driver = webdriver.Chrome(options=options)
stealth(driver,
languages=["en-US", "en"],
vendor="Google Inc.",
platform="Win32",
webgl_vendor="Intel Inc.",
renderer="Intel Iris OpenGL Engine",
fix_hairline=True,
)
driver.get("https://www.youtube.com/")
#input('login and click start')
cookies = pickle.load(open("cookies.pkl", "rb"))
for cookie in cookies:
driver.add_cookie(cookie)
driver.get(urlVideo)
#click comments button
while True:
try:
driver.find_element_by_xpath('/html/body').send_keys(Keys.PAGE_DOWN)
time.sleep(0.5)
driver.find_element_by_xpath('//*[@id="placeholder-area"]').click()
driver.find_element_by_xpath('//*[@id="contenteditable-root"]').send_keys(message)
break
except:
pass
time.sleep(2)
while True:
try:
driver.find_element_by_css_selector('.style-scope.ytd-button-renderer.style-primary.size-default').click()
break
except:
pass
input('ok')
Youtube使用多个机器人标志进行检测,如代理分数、selenium检测、用户代理、过去的帐户活动等。 你需要绕过所有这些来欺骗youtube! 我为一个客户制作了一个youtube机器人,为此我做了很多测试,这就是为什么我知道这一点。 你需要让你的chrome驱动程序不可检测,表现得像人而不是机器人
相关问题 更多 >
编程相关推荐