agid])) {
foreach ($g_flag_thread[$flagid] as &$val) {
flag_thread_filter($val);
}
flag_thread_set($flagid, $g_flag_thread[$flagid]);
}
}
return $g_flag_thread[$flagid];
}
// 设置缓存 $key = flagid / $val = flagid下tid数组
function flag_thread_set($key, $val)
{
global $g_flag_thread;
FALSE === $g_flag_thread and $g_flag_thread = website_get('flag_thread');
empty($g_flag_thread) and $g_flag_thread = array();
$g_flag_thread[$key] = $val;
return website_set('flag_thread', $g_flag_thread);
}
// 删除flag下tid缓存
function flag_thread_delete_cache($flagid)
{
global $g_flag_thread;
FALSE === $g_flag_thread and $g_flag_thread = website_get('flag_thread');
empty($g_flag_thread) and $g_flag_thread = array();
if (isset($g_flag_thread[$flagid])) {
unset($g_flag_thread[$flagid]);
website_set('flag_thread', $g_flag_thread);
}
return TRUE;
}
// Delete by tid / 通过tid删除flag下的主题和对应flagid缓存
function flag_thread_delete_by_tid($tid)
{
global $g_flag_thread;
FALSE === $g_flag_thread and $g_flag_thread = website_get('flag_thread');
if (empty($g_flag_thread)) {
$g_flag_thread = array();
} else {
$thread = well_thread_read_cache($tid);
$arrlist = flag_thread_find($tid, 1, $thread['flags']);
$flagarr = $ids = array();
foreach ($arrlist as $val) {
$flagarr[] = $val['flagid'];
$ids[] = $val['id'];
if (isset($g_flag_thread[$val['flagid']])) unset($g_flag_thread[$val['flagid']]);
}
website_set('flag_thread', $g_flag_thread);
// 主键更新
flag_update($flagarr, array('count-' => 1));
// 主键删除
flag_thread_delete($ids);
}
return TRUE;
}
// 主键删除 通过$flagid删除flag下的主题和对应flagid缓存
function flag_thread_delete_by_flagid($flagid)
{
global $g_flag_thread;
FALSE === $g_flag_thread and $g_flag_thread = website_get('flag_thread');
$read = flag_read_cache($flagid);
if (empty($read)) return TRUE;
$arrlist = flag_thread_find_by_flagid($flagid, 1, $read['count']);
if (empty($arrlist)) return TRUE;
$flagarr = $ids = array();
$n = 0;
foreach ($arrlist as $val) {
++$n;
$flagarr[] = $val['flagid'];
$ids[] = $val['id'];
if (isset($g_flag_thread[$flagid])) unset($g_flag_thread[$flagid]);
}
website_set('flag_thread', $g_flag_thread);
// 主键更新
flag_update($flagarr, array('count-' => $n));
// 主键删除
$r = flag_thread_delete($ids);
return $r;
}
?>break;
}
$r = array('filesize' => filesize($tmpfile), 'width' => $des_width, 'height' => $des_height);;
copy($tmpfile, $destfile);
is_file($tmpfile) && unlink($tmpfile);
imagedestroy($img_dst);
return $r;
}
/**
* 图片裁切
*
* @param string $sourcefile 原图片路径(绝对路径/abc.jpg)
* @param string $destfile 裁切后生成新名称(绝对路径/rename.jpg)
* @param int $clipx 被裁切图片的X坐标
* @param int $clipy 被裁切图片的Y坐标
* @param int $clipwidth 被裁区域的宽度
* @param int $clipheight 被裁区域的高度
* image_clip('xxx/x.jpg', 'xxx/newx.jpg', 10, 40, 150, 150)
*/
function well_image_clip($sourcefile, $destfile, $clipx, $clipy, $clipwidth, $clipheight, $getimgsize = '')
{
global $conf;
empty($getimgsize) AND $getimgsize = getimagesize($sourcefile);
if (empty($getimgsize)) {
return 0;
} else {
$imgwidth = $getimgsize[0];
$imgheight = $getimgsize[1];
if (0 == $imgwidth || 0 == $imgheight) {
return 0;
}
}
if (!function_exists('imagecreatefromjpeg')) {
copy($sourcefile, $destfile);
return filesize($destfile);
}
switch ($getimgsize[2]) {
case 1 :
$imgcolor = imagecreatefromgif($sourcefile);
break;
case 2 :
$imgcolor = imagecreatefromjpeg($sourcefile);
break;
case 3 :
$imgcolor = imagecreatefrompng($sourcefile);
break;
case 15: // WBMP
$imgcolor = imagecreatefromwbmp($sourcefile);
break;
case 18: // WEBP
$imgcolor = imagecreatefromwebp($sourcefile);
break;
}
if (!$imgcolor) return 0;
$img_dst = imagecreatetruecolor($clipwidth, $clipheight);
imagefill($img_dst, 0, 0, 0xFFFFFF);
imagecopyresampled($img_dst, $imgcolor, 0, 0, $clipx, $clipy, $imgwidth, $imgheight, $imgwidth, $imgheight);
$tmppath = isset($conf['tmp_path']) ? $conf['tmp_path'] : ini_get('upload_tmp_dir') . '/';
'/' == $tmppath AND $tmppath = './tmp/';
$tmpfile = $tmppath . md5($destfile) . '.tmp';
imagejpeg($img_dst, $tmpfile, 75);
$n = filesize($tmpfile);
copy($tmpfile, $destfile);
is_file($tmpfile) && unlink($tmpfile);
return $n;
}
function well_image_ext($filename) {
return strtolower(substr(strrchr($filename, '.'), 1));
}
?>
用Selenium操作网页,如何在打开网站的过程中,实现刷新,清除缓存的效果-软件玩家 - 软件改变生活!
在使用 Selenium 操作网页时,可以通过控制浏览器选项来实现刷新和清除缓存的效果。下面是使用 Python 和 Selenium 的示例代码:
刷新网页:
from selenium import webdriver
# 创建浏览器对象
driver = webdriver.Chrome()
# 打开网站
driver.get('https://www.example')
# 刷新网页
driver.refresh()
清除缓存:
from selenium import webdriver
# 创建浏览器对象
options = webdriver.ChromeOptions()
options.add_argument('--disable-application-cache') # 禁用应用程序缓存
options.add_argument('--disable-cache') # 禁用浏览器缓存
driver = webdriver.Chrome(chrome_options=options)
# 打开网站
driver.get('https://www.example')
在上述代码中,我们首先创建了一个浏览器对象,并打开了一个网站。然后,通过 refresh() 方法刷新页面,或者通过禁用缓存的选项来清除缓存。
请注意,示例代码中使用的是 Chrome 浏览器,如果你使用的是其他浏览器,可以相应地更改驱动程序和选项。另外,确保已正确安装 Selenium 和浏览器驱动程序。
本文标签:
缓存过程中效果操作网页
发表评论