Home > Article > Backend Development > PHP controls browser actions
Mac
1: Use phpLanguage writing control script
2: The script communicates with the chrome driver (chromedriver) program
3: chromedriver controls chrome execution operations
Process: php script => chromedriver => chrome
Wall circumvention tool
chrome browser
chromedriver
chromedriver
php-webdriver
Class library for php to communicate with chromedriver
Installationphp-webdriver Create a demo directory and execute
composer require<a href="http://www.php.cn/wiki/136.html" target="_blank"> facebook/webdriver</a>
<?php // An example of using php-webdriver. namespace Facebook\WebDriver; use Facebook\WebDriver\Remote\DesiredCapabilities; use Facebook\WebDriver\Remote\RemoteWebDriver; require_once('vendor/autoload.php'); //chromedriver默认端口 $host = 'http://localhost:9515'; $driver = RemoteWebDriver::create($host, DesiredCapabilities::chrome(), 50000); $driver->get('http://www.baidu.com'); $cookies = $driver->manage()->getCookies(); print_r($cookies); echo "The title is '" . $driver->getTitle() . "'\n"; echo "The current URI is '" . $driver->getCurrentURL() . "'\n"; //关闭浏览器 $driver->quit();
php demo.php
The above is the detailed content of PHP controls browser actions. For more information, please follow other related articles on the PHP Chinese website!