【发布时间】:2016-11-03 22:19:53
【问题描述】:
所以我有这个脚本
<?php
require_once('../_libTest/__init__.php');
class cacheTest
{
private $driver;
function __construct()
{
$host = 'http://localhost:4444/wd/hub'; // this is the default
//$capabilities = array(WebDriverCapabilityType::BROWSER_NAME => 'chrome');
$capabilities = DesiredCapabilities::chrome();
$options = new ChromeOptions();
/*$options->addExtensions(array(
'3.2.1_0.crx'
));*/
$capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
$this->driver = RemoteWebDriver::create($host, $capabilities,86400000,86400000);
}
function run()
{
$url = "https://www.google.com.au/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png";
$this->driver->get($url);
$filename = explode("/",$url);
$filename = end($filename);
$image = file_get_contents($url);
file_put_contents($filename,$image);
//$this->driver->quit();
}
}
$app = new cacheTest();
$app->run();
?>
使用 Selenium 独立服务器、Chrome Webdriver 和 this PHP Web Driver(已编辑以删除所有命名空间)以及包含在 __init__.php 文件中的所有文件,我可以打开 Chrome 浏览器窗口,转到然后使用file_get_contents 和file_put_contents 下载谷歌徽标图片
但是我想知道,因为为了节省时间,当我运行 Selenium 并直接导航到图像时,浏览器通常会缓存图像(因此 Chrome 的清除浏览历史记录中的选项“缓存图像和文件”) ,当我使用file_get_contents 时,这是获取浏览器的缓存图像还是从服务器获取新的图像?
【问题讨论】: