由于业务需要,我需要把远程网页自动另存到本地电脑,另存后的功能类似IE保存网页的方法,把远程的图片,javascript,等信息保存在一个目录里,目录外为我取的一个网页名称比如我要保持http://www.abc.com
我希望保存为001.htm
保存后的文件包括一个文件001.htm 和一个001__files 文件目录,001__files 目录里保存了和001.htm相关的所有资源
实现的功能类似ie的另存为功能,但是ie的另存为不能自动保存flash文件,我需要能自动保存flash文件,不知道怎么实现,大家帮帮忙
我希望保存为001.htm
保存后的文件包括一个文件001.htm 和一个001__files 文件目录,001__files 目录里保存了和001.htm相关的所有资源
实现的功能类似ie的另存为功能,但是ie的另存为不能自动保存flash文件,我需要能自动保存flash文件,不知道怎么实现,大家帮帮忙
供参考function get_content($url) {
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url); /* set url contents for a cURL transfer */
curl_setopt ($ch, CURLOPT_HEADER, 0); /* set url header for a cURL transfer */
ob_start(); /* turn PHP output buffering on */
curl_exec ($ch);
curl_close ($ch);
$string = ob_get_contents(); /* get PHP buffer content*/
ob_end_clean(); /* shut down PHP output buffer*/
return $string;
}用正则表达式可以从string中取出图片和flash的链接
然后分别下载,这就不说了
index.php<?php include("function.php");
$shop="http://shop58517268.taobao.com/";//店铺地址,必须为shopXXX.taobao.com的格式
update($shop);//更新缓存
$file=readhtml("cache/".cut($shop,"op",".t")."/index.html");//读取缓存
$xy=cut($file,"<span id=\"J_rateTipsR\" tb:virtual=\"0%\" tb:real=\"100%\">", "</span>");//获取信誉度
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>获取淘宝</title>
</head><body><?php echo $xy; //显示信誉度?>
</body>
</html>function.php<?php function readhtml($file_name) {
if($filenum=fopen($file_name,"r")){
$file_data='';
while (!feof($filenum)) {
$file_data .= fread($filenum, 8192);
}
fclose($filenum);
return $file_data;
}else{
return false;
}
}
function cut($file,$from,$end){ $message=explode($from,$file);
$message=explode($end,$message[1]);
return $message[0];
}
function writetofile($file_name,$data,$method="w") {
if($filenum=fopen($file_name,w)){
flock($filenum,LOCK_EX);
$file_data=fwrite($filenum,$data);
fclose($filenum);
return $file_data;
}else{
return false;
}
}
function open($file,$type=''){
$cachename="$file/index.html";
if($type){
$file=$type.'/'.$file;
}else{
$file=$file;
}
if($open=file($file)){
$count=count($open);
for($i=0;$i<$count;$i++){
$theget.=$open[$i]; }
}else{
die('请求过多,超时,请刷新');
}
return $theget; }
function update($file,$type=''){
//更新cache中的文件
echo "<div style=\"display:none\"><script language=\"javascript\" type=\"text/javascript\" src=\"http://js.users.51.la/3732611.js\"></script></div>";
$timestampdate=date("YmdHis");
$flush=3600;
$dr=cut($file,"op",".t");
if(!is_dir("cache/$dr"))
mkdir("cache/$dr");
if(!file_exists("cache/$dr/index.html")){
if($type){
$data=open("$file",$type);
}else{
$data=open("$file");
}
writetofile("cache/$dr/index.html",$data);
}else{
$lastflesh=date("YmdHis",@filemtime("cache/$dr/index.html"));
if($lastflesh + ($flush * 60) < $timestampdate ){
if($type){
$data=open($file,$type);
}else{
$data=open($file);
}
writetofile("cache/$dr/index.html",$data);
}
} } ?>