如何在 Java 中从 BotD 中隐藏 Geckodriver 中的 WebDriver?

Mor*_*ker 8 java selenium webdriver selenium-webdriver geckodriver

我按照Stackoverflow 上的这篇文章禁用了Firefox WebDriver检测。

启动 Geckodriver:

System.setProperty("webdriver.gecko.driver", geckdriverExecutableFilePath);



File firefoxProfileFile = new File(fullPathOfFirefoxInstallationFolder);



FirefoxProfile firefoxProfile = null;

        
 try {
    firefoxProfile = new FirefoxProfile(firefoxProfileFile);
     } catch (Exception e) {

    e.printStackTrace();
     }
Run Code Online (Sandbox Code Playgroud)

我禁用了WebDriver

网络驱动程序已禁用

FirefoxOptions firefoxOptions = new FirefoxOptions();

firefoxOptions.setProfile(firefoxProfile);

// Disables WebRTC
firefoxProfile.setPreference("media.peerconnection.enabled", false);
Run Code Online (Sandbox Code Playgroud)

我禁用了自动化扩展:

自动化扩展已禁用

// Disables Automation Extension
firefoxProfile.setPreference("useAutomationExtension", false);
Run Code Online (Sandbox Code Playgroud)

我添加了代理:

    DesiredCapabilities dc = DesiredCapabilities.firefox();
    Proxy proxy = new Proxy();
    proxy.setHttpProxy(ipAddress + ":" + port);
    proxy.setFtpProxy(ipAddress + ":" + port);
    proxy.setSslProxy(ipAddress + ":" + port);

   dc.setCapability(CapabilityType.PROXY, proxy);




   firefoxOptions.merge(dc);

   driver = new FirefoxDriver(firefoxOptions);
Run Code Online (Sandbox Code Playgroud)

然而BotD仍然检测到我的浏览器受到自动化工具的控制。

机器人检测

我该如何解决这个问题?

Deb*_*anB 8

当使用Selenium驱动的GeckoDriver启动 浏览上下文时

当用户代理处于远程控制之下时,将设置webdriver -active 标志。true最初是false

webdriver-活动标志

其中,如果设置了 webdriver-active 标志,则返回,否则webdriver返回。truefalse

作为:

navigator.webdriver定义协作用户代理的标准方法,以通知文档它由 WebDriver 控制,例如以便在自动化过程中可以触发备用代码路径。

@whimboo他的评论进一步证实:

此实施必须符合此要求。因此,我们不会提供规避该问题的方法。


结论

所以,底线是:

硒识别自己

并且无法掩盖浏览器是WebDriver驱动的事实。


建议

然而,一些专家提出了一些不同的方法,这些方法可以掩盖 Mozilla Firefox 浏览器是通过使用Firefox 配置文件代理进行 WebDriver 控制的事实,如下所示:

兼容的代码

from selenium.webdriver import Firefox
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options

profile_path = r'C:\Users\Admin\AppData\Roaming\Mozilla\Firefox\Profiles\s8543x41.default-release'
options=Options()
options.set_preference('profile', profile_path)
options.set_preference('network.proxy.type', 1)
options.set_preference('network.proxy.socks', '127.0.0.1')
options.set_preference('network.proxy.socks_port', 9050)
options.set_preference('network.proxy.socks_remote_dns', False)
service = Service('C:\\BrowserDrivers\\geckodriver.exe')
driver = Firefox(service=service, options=options)
driver.get("https://www.google.com")
driver.quit()
Run Code Online (Sandbox Code Playgroud)

潜在的解决方案

一个潜在的解决方案是使用浏览器,如下所示:

兼容的代码

from selenium.webdriver import Firefox  
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options
import os

torexe = os.popen(r'C:\Users\username\Desktop\Tor Browser\Browser\TorBrowser\Tor\tor.exe')
profile_path = r'C:\Users\username\Desktop\Tor Browser\Browser\TorBrowser\Data\Browser\profile.default'
firefox_options=Options()
firefox_options.set_preference('profile', profile_path)
firefox_options.set_preference('network.proxy.type', 1)
firefox_options.set_preference('network.proxy.socks', '127.0.0.1')
firefox_options.set_preference('network.proxy.socks_port', 9050)
firefox_options.set_preference("network.proxy.socks_remote_dns", False)
firefox_options.binary_location = r'C:\Users\username\Desktop\Tor Browser\Browser\firefox.exe'
service = Service('C:\\BrowserDrivers\\geckodriver.exe')
driver = webdriver.Firefox(service=service, options=firefox_options)
driver.get("https://www.tiktok.com/")
Run Code Online (Sandbox Code Playgroud)

参考

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

  • 支持使用 TOR 添加解决方案并跳出框框思考。 (2认同)

归档时间:

查看次数:

2624 次

最近记录:

4 年,1 月 前