使用Snoopy进行网页抓取
使用Snoopy可以快速实现一些抓取要做的工作。
1.fetch 抓取网页内容
2.submit 实现post操作
3.fetchlinks 获取网页中的所有连接地址
所有结果在属性results中,
如取得网页内容
require(’Snoopy.class.php’);
$snoopy = new Snoopy();
$snoopy->fetch(’http://www.coderhome.net/’);
$html = $snoopy->results;
echo $html ;
其它的大家自己看代码吧。
代码下载地址http://coderhome.net/ophtml/d597.html
共享我的获取网页基本内容的函数:
<?php
// 输入url将获得网页的charset,title,description
function parseSite($url) {
global $snoopy;
$snoopy->results = NULL;
$snoopy->fetch($url);
$html = $snoopy->results;
//charset
preg_match('/text\/html\;\s*charset\=([^>\"\']+)[\"\']?\s*\/?>/isx',$html,$match);
$charset = strtolower($match[1]);
//title
preg_match('/<title>([^<>]*)<\/title>/isx',$html,$match);
$title = $match[1];
$charset=='' && $charset='utf-8';
if ($charset!='' && $charset!='utf-8') {
$title = iconv($charset,'utf-8',$title);
}
//description
preg_match('/meta\sname\=[\'\"]?description[\'\"]?\scontent=[\'\"]?([^\'\"<>]+)[\'\"]?\s*\/?>/isx',$html,$match);
$description = $match[1];
if ($charset!='' && $charset!='utf-8') {
$description = iconv($charset,'utf-8',$description);
}
return array('url' => $url,'charset' => $charset,'title' => $title,'description' => $description,);
}
?>
使用Snoopy可以快速实现一些抓取要做的工作。
1.fetch 抓取网页内容
2.submit 实现post操作
3.fetchlinks 获取网页中的所有连接地址
所有结果在属性results中,
如取得网页内容
require(’Snoopy.class.php’);
$snoopy = new Snoopy();
$snoopy->fetch(’http://www.coderhome.net/’);
$html = $snoopy->results;
echo $html ;
其它的大家自己看代码吧。
代码下载地址http://coderhome.net/ophtml/d597.html
共享我的获取网页基本内容的函数:
<?php
// 输入url将获得网页的charset,title,description
function parseSite($url) {
global $snoopy;
$snoopy->results = NULL;
$snoopy->fetch($url);
$html = $snoopy->results;
//charset
preg_match('/text\/html\;\s*charset\=([^>\"\']+)[\"\']?\s*\/?>/isx',$html,$match);
$charset = strtolower($match[1]);
//title
preg_match('/<title>([^<>]*)<\/title>/isx',$html,$match);
$title = $match[1];
$charset=='' && $charset='utf-8';
if ($charset!='' && $charset!='utf-8') {
$title = iconv($charset,'utf-8',$title);
}
//description
preg_match('/meta\sname\=[\'\"]?description[\'\"]?\scontent=[\'\"]?([^\'\"<>]+)[\'\"]?\s*\/?>/isx',$html,$match);
$description = $match[1];
if ($charset!='' && $charset!='utf-8') {
$description = iconv($charset,'utf-8',$description);
}
return array('url' => $url,'charset' => $charset,'title' => $title,'description' => $description,);
}
?>
作者:noel@淘宝网女装新款秋装连衣裙裤子外套上衣_2012时尚女装新款 Ecmall二次开发-PHP技术
地址:http://www.laohucheng.com/post/314/
版权所有©转载时必须以链接形式注明作者和原始出处及本声明!
快速实现鼠标移上的浮动层显示
鼠标滑过停留效果
2009
16:16
461
0


