composer require facebook/webdriver
https://goo.gl/FCSwwD
java -jar selenium-server-standalone-3.14.0.jar
https://chromedriver.storage.googleapis.com/2.9/chromedriver_win32.zip
C:\Program Files (x86)\Google\Chrome\Application
编写测试代码(test.php):
阿克塞哈萨克族自治ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18980820575(备注:SSL证书合作)期待与您的合作!get($baseUrl);
echo consoleText($driver->getTitle()) . "\n"; //cmd.exe中文乱码,所以需转码
$topLists = $driver->findElement(WebDriverBy::className('container-top-wrapper'))->findElement(WebDriverBy::className('top-list-wrapper'))->findElements(WebDriverBy::tagName('li'));
foreach ($topLists as $topLi) {
$itemContent = $topLi->findElement(WebDriverBy::tagName('a'));
echo consoleText($itemContent->getAttribute('title')) . ' : ' . consoleText($itemContent->getAttribute('href')) . "\n";
}
//关闭浏览器
$driver->quit();
function consoleText($text, $pageEncoding = '', $consoleEncoding = '')
{
// windows
if (!$consoleEncoding) {
if (stristr(php_uname('s'), 'win')) {
$consoleEncoding = "GBK";
} else {
$consoleEncoding = 'UTF-8';
}
}
return exchangeEncoding($text, $pageEncoding, $consoleEncoding);
}
function exchangeEncoding($text, $pageEncoding = '', $targetEncoding = 'UTF-8')
{
if (!$pageEncoding) {
$pageEncoding = mb_detect_encoding($text, array("ASCII", 'UTF-8', "GB2312", "GBK", 'BIG5'));
}
if ($pageEncoding != $targetEncoding) {
return mb_convert_encoding($text,$targetEncoding,$pageEncoding);
}
return $text;
}
//切换至最后一个window
function switchToEndWindow($driver)
{
$arr = $driver->getWindowHandles();
foreach ($arr as $k => $v) {
if ($k == (count($arr) - 1)) {
$driver->switchTo()->window($v);
}
}
}
php test.php
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。