基于PHP/CURL/codeIgniter的Spider Webbot爬虫[8]-预判网站支持压缩,使用压缩和数据库保存数据
文章目录
预判压缩,如果支持压缩则优先使用
$header[]="Accept-Encoding:compress,gzip";
curl_setopt($curl_session,CURLOPT_HTTPHEADER,$header);
捕捉档案并且压缩范例
include("LIB_http.php");
// define the page
$target="http://xxx";
$ref="";
$method="GET";
$data_array="";
$web_page=http_get($target,$ref,$method,$data_array,EXCL_HEAD);
// 得到捕捉到的档案,并且进行压缩,并且输出压缩前后的大小
$unzip_size=strlen($webpage['FILE]);
$zip_size=strlen(gzcompress($web_page['FILE'],$compression_value=9));
//$noformat_size=strlen(strip_tags($web_page['FILE']));//strip_tags移除HTML标签
// 还可以添加trim移除所有空格
输出一张显示用的HTML表格(size)
<!DOCTYPE html>
<html lang="en">
<head>
<title>Welcome to Omoikane</title>
</head>
<body>
| Compression report for | ||
|---|---|---|
| Unzip | zip | |
| bytes | bytes | |
</body>
</html>
Page rendered in {elapsed_time} seconds
</body>
</html>

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论