php-webdriver怎么反反屏蔽绕过WebDriver检测

php-webdriver怎么反反屏蔽绕过WebDriver检测,网上找了半天没找到方法,最后还是无意发现一位网友发布的内容,记录一下。

直接上代码

disable-blink-features=AutomationControlled

下面是完整的代码,可以直接进行测试

<?php

// An example of using php-webdriver.
// Do not forget to run composer install before. You must also have Selenium server started and listening on port 4444.

namespace Facebook\WebDriver;

use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;

require_once('vendor/autoload.php');
// This is where Selenium server 2/3 listens by default. For Selenium 4, Chromedriver or Geckodriver, use http://localhost:4444/
$host = 'http://localhost:9515';
$capabilities = DesiredCapabilities::chrome();

    $options = new ChromeOptions();
    $options->addArguments(
        [
            '--no-sandbox',                        // 解决DevToolsActivePort文件不存在的报错
            'window-size=1080x1920',               // 指定浏览器分辨率
            '--disable-gpu',                       // 谷歌文档提到需要加上这个属性来规避bug
            '--hide-scrollbars',                   // 隐藏滚动条, 应对一些特殊页面
            'blink-settings=imagesEnabled=false',  // 不加载图片, 提升速度
           // '--ignore-certificate-errors',
           // '--ignore-ssl-errors',
          // '--incognito',  //无痕模式启动
           '--start-maximized',  //全屏模式运行
           'disable-blink-features=AutomationControlled', //非常重要,这一个可以绕过WebDriver检测
           //'--disable-setuid-sandbox',
            //'--headless',                          // 浏览器不提供可视化页面
        ]
    );
    $capabilities->setCapability(ChromeOptions::CAPABILITY, $options);

$driver = RemoteWebDriver::create($host, $capabilities);

// navigate to Selenium page on Wikipedia
$driver->get('https://intoli.com/blog/not-possible-to-block-chrome-headless/chrome-headless-test.html');
$html_selenium = $driver->getPageSource();
echo $html_selenium;
// close the browser
$driver->quit();
?>

最后通过后是这样的截图

php-webdriver怎么反反屏蔽绕过WebDriver检测

参考网址:https://www.cnpython.com/qa/1291905

到此为止。

发布者:彬彬笔记,转载请注明出处:https://www.binbinbiji.com/php/2338.html

(2)
彬彬笔记彬彬笔记
上一篇 2022年6月5日 17:11
下一篇 2022年6月6日 23:33

相关推荐

发表回复

登录后才能评论
蜀ICP备14017386号-13