php-webdriver concise tutorial

  1. Install
composer require php-webdriver/webdriver
  1. use
require_once 'vendor/autoload.php';
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;

$chromeDriverPath = __DIR__ . '\chromedriver.exe';
// 这里需要填写你chromedriver的实际路径
shell_exec($chromeDriverPath);

$options = new ChromeOptions();
$options->addArguments(['--headless']);
$capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
$driver = RemoteWebDriver::create('http://localhost:9515', $capabilities);
$tag_url = "http://www.baidu.com";// 你需要爬虫的网站
$driver->get($tag_url);
echo $driver->getTitle();

OK~! It's that simple, just copy the above code,
if there is no accident, it will output "Baidu, you will know"
If an error is reported, please download the chromdriver that is consistent with your Google Chrome version

Guess you like

Origin blog.csdn.net/u010775335/article/details/128587110