Re: Snoopy功能强大的模拟浏览器方法的PHP类
基础用法
[code]
include "Snoopy.class.php";
$snoopy = new Snoopy;
$snoopy->proxy_host = "http://www.nowamagic.net/librarys/veda/";
$snoopy->proxy_port = "80";
$snoopy->agent = "(compatible; MSIE 4.01; MSN 2.5; AOL 4.0; Windows 98)";
$snoopy->referer = "http://www.4wei.cn";
$snoopy->cookies["SessionID"] = 238472834723489l;
$snoopy->cookies["favoriteColor"] = "RED";
$snoopy->rawheaders["Pragma"] = "no-cache";
$snoopy->maxredirs = 2;
$snoopy->offsiteok = false;
$snoopy->expandlinks = false;
$snoopy->user = "joe";
$snoopy->pass = "bloe";
if($snoopy->fetchtext("http://www.4wei.cn")){
echo "<PRE>".htmlspecialchars($snoopy->results)."</PRE>n";
}else{
echo "error fetching document: ".$snoopy->error."n";
}[/code]
获取指定url内容
[code]
$url = "http://www.nowamagic.net/librarys/veda/";
include("snoopy.php");
$snoopy = new Snoopy;
$snoopy->fetch($url); //获取所有内容
echo $snoopy->results; //显示结果
//可选以下
//$snoopy->fetchtext //获取文本内容(去掉html代码)
//$snoopy->fetchlinks //获取链接
//$snoopy->fetchform //获取表单[/code]
表单提交
[code]$formvars["username"] = "admin";
$formvars["pwd"] = "admin";
$action = "http://www.nowamagic.net/librarys/veda/";//表单提交地址
$snoopy->submit($action,$formvars);//$formvars为提交的数组
echo $snoopy->results; //获取表单提交后的 返回的结果
//可选以下
$snoopy->submittext; //提交后只返回 去除html的 文本
$snoopy->submitlinks;//提交后只返回 链接
?>
[/code]