【问题标题】:When I add a comment on YouTube it does not appear python selenium当我在 YouTube 上添加评论时,它不会出现 python selenium
【发布时间】:2021-07-03 07:35:31
【问题描述】:

我使用以下代码在YouTube上添加评论但是当我添加评论时,刷新页面后它没有出现。 但是当我在我的个人浏览器中发表评论时,评论会正常显示 我认为 Google 知道我使用的是非个人浏览器,因此它不会显示评论 有解决这个问题的想法吗?

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')

【问题讨论】:

  • 在提交后用 selenium 截屏(可能要等几秒钟)......谷歌很可能有机器人检测的东西......我无法想象他们喜欢人们自动化 cmets
  • 你的意思是截图吗?

标签: python python-3.x selenium selenium-webdriver


【解决方案1】:

Youtube 使用多个标志来检测机器人,例如代理分数、硒检测、用户代理、过去的帐户活动等。 你需要绕过所有这些来欺骗 youtube! 我为客户制作了一个 youtube 机器人,为此我做了很多测试,这就是我知道这一点的原因。 你需要让你的 chrome 驱动程序无法被检测到,并且表现得像人类而不是机器人。

【讨论】:

  • 您好,先生,我怎样才能使 chrome 驱动程序无法检测到,并且表现得像人类而不是机器人!
  • 不和谐@odddkidout#3154
  • 我没有不和谐给我你的 twitter 或 instagram
  • 相同的@odddkidout
  • 我可以给你发消息,我的推特用户是(user.zahouani)
猜你喜欢
  • 2014-06-12
  • 1970-01-01
  • 1970-01-01
  • 2011-04-09
  • 2013-08-01
  • 1970-01-01
  • 2013-01-16
  • 1970-01-01
  • 2018-01-26
相关资源
最近更新 更多