Javascript 网站能否检测到您何时将硒与chromedriver一起使用?

Javascript 网站能否检测到您何时将硒与chromedriver一起使用?,javascript,python,google-chrome,selenium,selenium-chromedriver,captcha,recaptcha,user-agent,2captcha,recaptcha-v3,checkbox,Javascript,Python,Google Chrome,Selenium,Selenium Chromedriver,Captcha,Recaptcha,User Agent,2captcha,Recaptcha V3,Checkbox,我一直在用Chromedriver测试Selenium,我注意到有些页面可以检测到您正在使用Selenium,即使根本没有自动化。即使我只是通过Selenium和Xephyr使用Chrome手动浏览,我也经常会看到一个页面,上面说检测到可疑活动。我检查了我的用户代理和浏览器指纹,它们与普通的Chrome浏览器完全相同 当我用普通的Chrome浏览器浏览这些网站时,一切正常,但当我使用Selenium时,我就被检测到了 理论上,chromedriver和Chrome在任何Web服务器上看起来都应该

我一直在用Chromedriver测试Selenium,我注意到有些页面可以检测到您正在使用Selenium,即使根本没有自动化。即使我只是通过Selenium和Xephyr使用Chrome手动浏览,我也经常会看到一个页面,上面说检测到可疑活动。我检查了我的用户代理和浏览器指纹,它们与普通的Chrome浏览器完全相同

当我用普通的Chrome浏览器浏览这些网站时,一切正常,但当我使用Selenium时,我就被检测到了

理论上,chromedriver和Chrome在任何Web服务器上看起来都应该完全相同,但不知何故它们可以检测到它

如果您想要一些测试代码,请尝试以下方法:

from pyvirtualdisplay import Display
from selenium import webdriver

display = Display(visible=1, size=(1600, 902))
display.start()
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--disable-extensions')
chrome_options.add_argument('--profile-directory=Default')
chrome_options.add_argument("--incognito")
chrome_options.add_argument("--disable-plugins-discovery");
chrome_options.add_argument("--start-maximized")
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.delete_all_cookies()
driver.set_window_size(800,800)
driver.set_window_position(0,0)
print 'arguments done'
driver.get('http://stubhub.com')
如果你浏览stubhub,你会在一两个请求中被重定向和“阻止”。我一直在调查这个问题,但我不知道他们如何判断用户正在使用Selenium

他们是怎么做到的

我在Firefox中安装了Selenium IDE插件,但当我在普通Firefox浏览器中访问stubhub.com时,只使用了额外的插件而被禁止

当我使用Fiddler查看来回发送的HTTP请求时,我注意到“假浏览器”请求通常在响应头中没有缓存

这样的结果表明,当您使用webdriver时,应该没有办法检测到。但这一证据表明情况并非如此

该网站上传了一个指纹到他们的服务器上,但我检查了一下,Selenium的指纹与使用Chrome时的指纹相同

这是他们发送到服务器的指纹有效载荷之一: {“appName”:“Netscape”,“platform”:“Linux86_64”,“cookies”:1,“syslang”:“en-US”,“userlang”:“en-US”,“cpu”:“productSub”:“20030107”,“setTimeout”:1,“setInterval”:1,“plugins”:{“0”:“ChromePDViewer”,“1”:“ShockwaveFlash”,“2”:“WidevineContentDecryptionModule”,“3”:“NativeClient”,“4”:“ChromePDViewer”},“mimeTypes”:{“0”:“application/pdf”,“1”:“ShockwaveFlashapplication/x-shockwave-flash”,“2:“FutureSplayerApplication/FutureSplayerApplication”,“3:“WideVineContentDecryptionModuleApplications/x-ppapi-widevine-cdm”,“4:“NativeClientExecutableapplication/x-nacl”,“5:“PortableNativeClientExecutableapplication/x-pnacl”,“6:“PortableDocumentFormatapplication/x-google-chrome-pdf”,屏幕:{”宽度字体:{“0”:“monospace”,“1”:“DejaVuSerif”,“2”:“Georgia”,“3”:“DejaVuSans”,“4”:“投石机”,“5”:“Verdana”,“6”:“AndaleMono”,“7”:“DejaVuSansMono”,“8”:“LiberationMono”,“9”:“NimbusMono”,“10”:“CourierNew”,“11”:“Courier”}

硒和铬的含量相同


VPN只用于一次使用,但在我加载第一个页面后会被检测到。显然,一些JavaScript正在运行以检测Selenium。

听起来它们好像在web应用程序防火墙后面。看看modsecurity,看看它们是如何工作的

实际上,您要问的是如何进行机器人检测规避。这不是SeleniumWebDriver的用途。它用于测试您的web应用程序,而不影响其他web应用程序。这是可能的,但基本上,您必须查看WAF在其规则集中查找的内容,如果可以的话,请特别避免使用selenium。即使这样,它可能仍然不起作用,因为您不知道他们正在使用什么WAF

您做了正确的第一步,即伪造用户代理。如果这样做不起作用,那么WAF已经就位,您可能需要更加小心


从另一个答案来看。首先确保您的用户代理设置正确。可能是它击中了本地web服务器或嗅探出了流量。

即使您发送了所有正确的数据(例如,Selenium没有显示为扩展,您有一个合理的分辨率/位深度,&c),有许多服务和工具可以分析访问者的行为,以确定参与者是用户还是自动化系统

例如,访问一个站点,然后在不到一秒钟的时间内将鼠标直接移动到相关按钮,立即执行某些操作,这是任何用户实际上都不会做的事情


它也可能是一个有用的调试工具来使用一个网站,例如检查你的浏览器有多独特;它还将帮助您验证是否有任何特定参数指示您正在运行Selenium

如果使用webdriver,Firefox会设置
window.navigator.webdriver===true
。这是根据一个较旧的规范(例如:)进行的,但除了附录中一些非常模糊的措辞外,我在中找不到它

测试是在文件中的selenium代码中进行的,文件末尾的注释是“当前仅在firefox中实现”,但我无法通过一些简单的
grep
ing来识别该方向的任何代码,无论是在当前(41.0.2)的firefox发布树中还是在Chromium树中


我还在firefox驱动程序中找到了一条关于指纹识别的评论。该代码仍在昨天下载的Selenium GIT master中,
javascript/firefox driver/extension/content/server.js
,其中有一条注释链接到当前w3c webdriver规范中措辞稍有不同的附录。

用以下代码编写一个html页面。您将看到,在DOM中,selenium在outerHTML中应用了webdriver属性


尝试将selenium与chrome的特定用户配置文件一起使用,这样您就可以将其作为特定用户使用并定义任何您想要的内容,这样做时它将作为“真实”用户运行,使用一些process explorer查看chrome进程,您将看到标签的不同之处

例如:

username = os.getenv("USERNAME")
userProfile = "C:\\Users\\" + username + "\\AppData\\Local\\Google\\Chrome\\User Data\\Default"
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir={}".format(userProfile))
# add here any tag you want.
options.add_experimental_option("excludeSwitches", ["ignore-certificate-errors", "safebrowsing-disable-download-protection", "safebrowsing-disable-auto-update", "disable-client-side-phishing-detection"])
chromedriver = "C:\Python27\chromedriver\chromedriver.exe"
os.environ["webdriver.chrome.driver"] = chromedriver
browser = webdriver.Chrome(executable_path=chromedriver, chrome_options=options)

chrome标签列表

正如我们在问题和发布的答案中已经指出的那样,这里有一个反网络抓取和一个称为in play的机器人检测服务。而且,据t
try {
 if (window.document.documentElement.getAttribute("webdriver")) return !+[]
} catch (IDLMrxxel) {}
try {
 if ("_Selenium_IDE_Recorder" in window) return !+""
} catch (KknKsUayS) {}
try {
 if ("__webdriver_script_fn" in document) return !+""
function getPageCache(opt_doc) {
  var doc = opt_doc || document;
  //var key = '$cdc_asdjflasutopfhvcZLmcfl_';
  var key = 'randomblabla_';
  if (!(key in doc))
    doc[key] = new Cache();
  return doc[key];
}
runBotDetection = function () {
    var documentDetectionKeys = [
        "__webdriver_evaluate",
        "__selenium_evaluate",
        "__webdriver_script_function",
        "__webdriver_script_func",
        "__webdriver_script_fn",
        "__fxdriver_evaluate",
        "__driver_unwrapped",
        "__webdriver_unwrapped",
        "__driver_evaluate",
        "__selenium_unwrapped",
        "__fxdriver_unwrapped",
    ];

    var windowDetectionKeys = [
        "_phantom",
        "__nightmare",
        "_selenium",
        "callPhantom",
        "callSelenium",
        "_Selenium_IDE_Recorder",
    ];

    for (const windowDetectionKey in windowDetectionKeys) {
        const windowDetectionKeyValue = windowDetectionKeys[windowDetectionKey];
        if (window[windowDetectionKeyValue]) {
            return true;
        }
    };
    for (const documentDetectionKey in documentDetectionKeys) {
        const documentDetectionKeyValue = documentDetectionKeys[documentDetectionKey];
        if (window['document'][documentDetectionKeyValue]) {
            return true;
        }
    };

    for (const documentKey in window['document']) {
        if (documentKey.match(/\$[a-z]dc_/) && window['document'][documentKey]['cache_']) {
            return true;
        }
    }

    if (window['external'] && window['external'].toString() && (window['external'].toString()['indexOf']('Sequentum') != -1)) return true;

    if (window['document']['documentElement']['getAttribute']('selenium')) return true;
    if (window['document']['documentElement']['getAttribute']('webdriver')) return true;
    if (window['document']['documentElement']['getAttribute']('driver')) return true;

    return false;
};
function d() {
try {
    if (window.document.$cdc_asdjflasutopfhvcZLmcfl_.cache_)
        return !0
} catch (e) {}

try {
    //if (window.document.documentElement.getAttribute(decodeURIComponent("%77%65%62%64%72%69%76%65%72")))
    if (window.document.documentElement.getAttribute("webdriver"))
        return !0
} catch (e) {}

try {
    //if (decodeURIComponent("%5F%53%65%6C%65%6E%69%75%6D%5F%49%44%45%5F%52%65%63%6F%72%64%65%72") in window)
    if ("_Selenium_IDE_Recorder" in window)
        return !0
} catch (e) {}

try {
    //if (decodeURIComponent("%5F%5F%77%65%62%64%72%69%76%65%72%5F%73%63%72%69%70%74%5F%66%6E") in document)
    if ("__webdriver_script_fn" in document)
        return !0
} catch (e) {}
vim /path/to/chromedriver
perl -pi -e 's/cdc_/dog_/g' /path/to/chromedriver
grep "cdc_" /path/to/chromedriver
package main

import (
    "github.com/tebeka/selenium"
    "github.com/tebeka/selenium/chrome"
)

func main() {

caps := selenium.Capabilities{
    "browserName": "chrome",
}

chromeCaps := chrome.Capabilities{
    Path:            "/path/to/chrome-binary",
    ExcludeSwitches: []string{"enable-automation"},
}
caps.AddChrome(chromeCaps)

wd, err := selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d/wd/hub", 4444))
}
chromeOptions.addArguments("--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36");
var options = new ChromeOptions();

// hide selenium
options.AddExcludedArguments(new List<string>() { "enable-automation" });

var driver = new ChromeDriver(ChromeDriverService.CreateDefaultService(), options);
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from fake_useragent import UserAgent

options = Options()
ua = UserAgent()
userAgent = ua.random
print(userAgent)
options.add_argument(f'user-agent={userAgent}')
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\WebDrivers\ChromeDriver\chromedriver_win32\chromedriver.exe')
driver.get("https://www.google.co.in")
driver.quit()
from selenium import webdriver

driver = webdriver.Chrome(executable_path=r'C:\WebDrivers\chromedriver.exe')
print(driver.execute_script("return navigator.userAgent;"))
# Setting user agent as Chrome/83.0.4103.97
driver.execute_cdp_cmd('Network.setUserAgentOverride', {"userAgent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36'})
print(driver.execute_script("return navigator.userAgent;"))
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
  "source": """
    Object.defineProperty(navigator, 'webdriver', {
      get: () => undefined
    })
  """
})
from selenium import webdriver
driver = webdriver.Chrome()
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
    "source":
        "const newProto = navigator.__proto__;"
        "delete newProto.webdriver;"
        "navigator.__proto__ = newProto;"
    })