mac
流程: php脚本 => chromedriver => chrome
立即学习“PHP免费学习笔记(深入)”;
翻墙工具
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
以上就是PHP控制浏览器动作的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号