Rumah >pembangunan bahagian belakang >tutorial php >PHP控制浏览器动作
Mac
流程: php脚本 => chromedriver => chrome
翻墙工具
chrome浏览器
chromedriver
chrome驱动程序
php-webdriver
php与chromedriver通信的类库
1:安装php-webdriver
创建demo目录,在目录中执行 composer <a href="http://www.php.cn/wiki/136.html" target="_blank">require</a> facebook/webdriver
2:下载chromedriver,双击运行
3:在demo目录,创建demo.php文件
<?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();
4:运行demo.phpphp demo.php
Atas ialah kandungan terperinci PHP控制浏览器动作. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!