chromeOptions 添加选项: --disable-blink-features=AutomationControlled

$options = [
            '--no-sandbox',                        // 解决DevToolsActivePort文件不存在的报错
            'window-size=1400,1000',                // 指定浏览器分辨率
            //   '--disable-gpu',                       // 谷歌文档提到需要加上这个属性来规避bug
            //   '--hide-scrollbars',                   // 隐藏滚动条, 应对一些特殊页面
            //  'blink-settings=imagesEnabled=false',  // 不加载图片, 提升速度
    '--disable-blink-features=AutomationControlled',
    '--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.41',
];
$capabilitiesOptions = array_merge([
    WebDriverCapabilityType::BROWSER_NAME => WebDriverBrowserType::CHROME,
    WebDriverCapabilityType::PLATFORM     => WebDriverPlatform::ANY,
], $capabilitiesOptions);
$capabilities = new DesiredCapabilities($capabilitiesOptions);
$chromeOptions = new ChromeOptions();
$chromeOptions->addArguments($options);
$chromeOptions->setExperimentalOption('useAutomationExtension',false);
$chromeOptions->setExperimentalOption('excludeSwitches', ['enable-automation', 'enable-logging']);
.....

相关更多的讨论:
https://stackoverflow.com/questions/33225947/can-a-website-detect-when-you-are-using-selenium-with-chromedriver

https://stackoverflow.com/questions/33225947/can-a-website-detect-when-you-are-using-selenium-with-chromedriver/41220267#41220267

https://stackoverflow.com/questions/53039551/selenium-webdriver-modifying-navigator-webdriver-flag-to-prevent-selenium-detec/53040904#53040904

标签: none

添加新评论