php 模仿蜘蛛抓取内容并分析
2014-08-07 13:31
323 查看
这是一款模仿baidu,google抓取你网页时的样子哦,下面就是代码看看吧。
header("Content-Type:text/html;charset=gbk");
$message=$_POST['message'];
$contents = @file_get_contents("$message");
if($contents=="Forbidden"){
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, "$message");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER,
1);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0
(compatible; MSIE 6.0; Windows NT 5.1; SV1)");
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,
$timeout);
$contents = curl_exec($ch);
curl_close($ch);
}
preg_match_all("/<title(.*?)</title>/is",$contents,$title);
preg_match_all("/<meta(.*?)>/is",$contents,$meta);
preg_match_all("/<body(.*?)body>/is",$contents,$body);
echo
'title:'.strip_tags($title[0][0]).'<br><br>';
for($i=0;$i<count($meta[0]);$i++){
if(preg_match("/keywords/i",$meta[0][$i])){
preg_match_all("/content="(.*?)"/is",$meta[0][$i],$keywords);
}
if(preg_match("/description/i",$meta[0][$i])){
preg_match_all("/content="(.*?)"/is",$meta[0][$i],$description);
}
}
echo
'keywords:'.strip_tags($keywords[1][0]).'<br><br>';
echo
'description:'.strip_tags($description[1][0]).'<br><br>';
echo 'body:'.strip_tags($body[0][0]);
?>
更多详细内容请查看:http://www.111cn.net/phper/18/67a3af30619696432294fd5c2731f13f.htm
header("Content-Type:text/html;charset=gbk");
$message=$_POST['message'];
$contents = @file_get_contents("$message");
if($contents=="Forbidden"){
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, "$message");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER,
1);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0
(compatible; MSIE 6.0; Windows NT 5.1; SV1)");
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,
$timeout);
$contents = curl_exec($ch);
curl_close($ch);
}
preg_match_all("/<title(.*?)</title>/is",$contents,$title);
preg_match_all("/<meta(.*?)>/is",$contents,$meta);
preg_match_all("/<body(.*?)body>/is",$contents,$body);
echo
'title:'.strip_tags($title[0][0]).'<br><br>';
for($i=0;$i<count($meta[0]);$i++){
if(preg_match("/keywords/i",$meta[0][$i])){
preg_match_all("/content="(.*?)"/is",$meta[0][$i],$keywords);
}
if(preg_match("/description/i",$meta[0][$i])){
preg_match_all("/content="(.*?)"/is",$meta[0][$i],$description);
}
}
echo
'keywords:'.strip_tags($keywords[1][0]).'<br><br>';
echo
'description:'.strip_tags($description[1][0]).'<br><br>';
echo 'body:'.strip_tags($body[0][0]);
?>
更多详细内容请查看:http://www.111cn.net/phper/18/67a3af30619696432294fd5c2731f13f.htm
相关文章推荐
- 【PHP&nbsp;使用&nbsp;CURL&nbsp;同步抓取多個網頁…
- 使用PHP简单网页抓取和内容分析
- 使用PHP简单网页抓取和内容分析
- python&php数据抓取、爬虫分析与中介,有网址案例
- 使用PHP简单网页抓取和内容分析
- php抓取网页内容方法分析
- php&nbsp;读取指定字符中间内容代码
- php网页分析 内容抓取 爬虫 文件分析
- python&php数据抓取、爬虫分析与中介,有网址案例
- 使用php方法curl抓取AJAX异步内容思路分析及代码分享
- PHP 抓取 网站标题 <title></tile>里的内容
- 关于 Python 数据抓取 & 分析 & 机器学习 & 挖掘 & 神经网络 内容的分享。
- 使用php方法curl抓取AJAX异步内容思路分析及代码分享
- php抓取文章内容分析
- 使用PHP简单网页抓取和内容分析
- 使用PHP简单网页抓取和内容分析
- 使用PHP简单网页抓取和内容分析
- PHP session的详细分析
- PHP抓取网页内容
- PHP 抓取和分析