如何从 Java 中的 BotD 中隐藏 Geckodriver 中的 WebDriver? [英] How to Conceal WebDriver in Geckodriver from BotD in Java?

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

问题描述

我按照 确认:

<块引用><块引用>

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


结论

所以,底线是:

<块引用>

Selenium 自我识别

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


建议

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

<块引用>

兼容 代码

从 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()


潜在解决方案

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

<块引用>

兼容 代码

从 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/")


参考文献

您可以在

中找到一些相关的详细讨论

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 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:

compatible 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 browser as follows:

compatible 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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆