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

How to Conceal WebDriver in Geckodriver from BotD in Java?(如何从 Java 中的 BotD 中隐藏 Geckodriver 中的 WebDriver?)
本文介绍了如何从 Java 中的 BotD 中隐藏 Geckodriver 中的 WebDriver?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照 确认:

<块引用><块引用>

此实现必须符合此要求.像这样我们不会提供规避方法.


结论

所以,底线是:

<块引用>

Selenium 自我识别

并且无法隐藏浏览器是 WebDriver 驱动.


建议

然而,一些权威人士提出了一些不同的方法,这些方法可以掩盖 Mozilla Firefox 浏览器是通过使用 Firefox 配置文件代理如下:

<块引用>

selenium4 兼容 python 代码

从 selenium.webdriver 导入 Firefox从硒导入网络驱动程序从 selenium.webdriver.firefox.service 导入服务从 selenium.webdriver.firefox.options 导入选项profile_path = r'C:UsersAdminAppDataRoamingMozillaFirefoxProfiless8543x41.default-release'选项=选项()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)服务 = 服务('C:\BrowserDrivers\geckodriver.exe')驱动程序= Firefox(服务=服务,选项=选项)driver.get("https://www.google.com")driver.quit()


潜在解决方案

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

<块引用>

selenium4 兼容 python 代码

从 selenium.webdriver 导入 Firefox从硒导入网络驱动程序从 selenium.webdriver.firefox.service 导入服务从 selenium.webdriver.firefox.options 导入选项导入操作系统torexe = os.popen(r'C:UsersusernameDesktopTor BrowserBrowserTorBrowserTor	or.exe')profile_path = r'C:UsersusernameDesktopTor BrowserBrowserTorBrowserDataBrowserprofile.default'firefox_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:UsersusernameDesktopTor BrowserBrowserfirefox.exe'服务 = 服务('C:\BrowserDrivers\geckodriver.exe')驱动程序= webdriver.Firefox(服务=服务,选项=firefox_options)driver.get("https://www.tiktok.com/")


参考文献

您可以在

中找到一些相关的详细讨论
  • 如何通过 Python 使用 GeckoDriver 和 Selenium 启动 Tor Browser 9.5,使用默认 Firefox 到 68.9.0esr
  • 如何使用 Python 连接 Tor 浏览器
  • 如何在 Chrome 浏览器中使用 Tor通过硒

I followed this post on Stackoverflow to disable Firefox WebDriver detection.

Launch 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();
     }

I disabled WebDriver:

WebDriver Disabled

FirefoxOptions firefoxOptions = new FirefoxOptions();

firefoxOptions.setProfile(firefoxProfile);

// Disables WebRTC
firefoxProfile.setPreference("media.peerconnection.enabled", false);

I disabled Automation Extensions:

Automation Extension Disabled

// Disables Automation Extension
firefoxProfile.setPreference("useAutomationExtension", false);

I added Proxy:

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

Yet BotD still detects my browser as being controlled by automation tool.

BotD Detection

How can I solve this?

解决方案

When using Selenium driven GeckoDriver initiated firefox Browsing Context

The webdriver-active flag is set to true when the user agent is under remote control. It is initially false.

where, webdriver returns true if webdriver-active flag is set, false otherwise.

As:

navigator.webdriver Defines a standard way for co-operating user agents to inform the document that it is controlled by WebDriver, for example so that alternate code paths can be triggered during automation.

Further @whimboo in his comments confirmed:

This implementation have to be conformant to this requirement. As such we will not provide a way to circumvent that.


Conclusion

So, the bottom line is:

Selenium identifies itself

and there is no way to conceal the fact that the browser is WebDriver driven.


Recommendations

However some pundits have suggested some different approaches which can conceal the fact that the Mozilla Firefox browser is WebDriver controled through the usage of Firefox Profiles and Proxies as follows:

selenium4 compatible python code

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:UsersAdminAppDataRoamingMozillaFirefoxProfiless8543x41.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()


Potential Solution

A potential solution would be to use the tor browser as follows:

selenium4 compatible python code

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:UsersusernameDesktopTor BrowserBrowserTorBrowserTor	or.exe')
profile_path = r'C:UsersusernameDesktopTor BrowserBrowserTorBrowserDataBrowserprofile.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:UsersusernameDesktopTor BrowserBrowserfirefox.exe'
service = Service('C:\BrowserDrivers\geckodriver.exe')
driver = webdriver.Firefox(service=service, options=firefox_options)
driver.get("https://www.tiktok.com/")


References

You can find a couple of relevant detailed discussions in

  • How to initiate a Tor Browser 9.5 which uses the default Firefox to 68.9.0esr using GeckoDriver and Selenium through Python
  • How to connect to Tor browser using Python
  • How to use Tor with Chrome browser through Selenium

这篇关于如何从 Java 中的 BotD 中隐藏 Geckodriver 中的 WebDriver?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How can create a producer using Spring Cloud Kafka Stream 3.1(如何使用Spring Cloud Kafka Stream 3.1创建制片人)
Insert a position in a linked list Java(在链接列表中插入位置Java)
Did I write this constructor properly?(我是否正确地编写了这个构造函数?)
Head value set to null but tail value still gets displayed(Head值设置为空,但仍显示Tail值)
printing nodes from a singly-linked list(打印单链接列表中的节点)
Control namespace prefixes in web services?(控制Web服务中的命名空间前缀?)