如何让 python selenium 不易被检测到?

问题描述 投票:0回答:1

好的,所以我正在为这个网站制作一个机器人来自动创建帐户。我正在使用旋转 ipv4 代理和其他一些反检测的东西,但每次仍然被检测到。有什么想法吗?

这是我初始化驱动程序的方式以及我使用的选项。

proxy = random.choice(proxys)
ua = UserAgent()
userAgent = ua.random

def main():
    options = webdriver.ChromeOptions()
    options.add_argument(r'--user-data-dir=my chrome user data directory here')
    options.add_argument(f'--proxy-server={proxy}')
    options.add_argument("start-maximized")
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option('useAutomationExtension', False)
    options.add_argument(f'user-agent={userAgent}')
    driver = uc.Chrome(service=Service(ChromeDriverManager(cache_valid_range=30).install()),options=options)
    driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
    print(driver.execute_script("return navigator.userAgent;"))
    sleep(1)
    while True:
        create_account(driver, catchall)

我也尝试过 chrome 配置文件,但我无法充分利用这些配置文件,并且想知道如何以某种方式实现这些配置文件。因为似乎在网站检测到我是机器人之后,我使用的 chrome 配置文件不再有效。

我每次都被网站屏蔽,几乎不管怎样。尽管有时在我进行一些随机更改后它确实会发生。但我希望现在一切都能正常工作,因为几乎所有他们能检测到的东西都在改变。

python selenium-webdriver selenium-chromedriver browser-automation
1个回答
0
投票

selenium-stealth

要使 Python-Selenium 几乎检测不到,您最好的选择是使用 selenium-stealth 哪个:

  • 通过所有公共机器人测试。
  • Selenium 可以登录谷歌账户。
  • 保持正常的 reCAPTCHA v3 分数

示范

  • 代码块:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.chrome.service import Service
    from selenium_stealth import stealth
    import time
    options = Options()
    options.add_argument("start-maximized")
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option('useAutomationExtension', False)
    s = Service('C:\\BrowserDrivers\\chromedriver.exe')
    driver = webdriver.Chrome(service=s, options=options)
    
    # Selenium Stealth settings
    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://bot.sannysoft.com")
    time.sleep(5)
    driver.save_screenshot("sannysoft.png")
    driver.quit()
    
  • 截图:

sannysoft.png


参考文献

您可以在以下位置找到一些相关的详细讨论:

© www.soinside.com 2019 - 2024. All rights reserved.