$url = "http://www.taoav.com"; include("snoopy.php"); $snoopy = new Snoopy; $snoopy->fetch($url); //获取所有内容 echo $snoopy->results; //显示结果 $snoopy->fetchtext //获取文本内容(去掉html代码) $snoopy->fetchlinks //获取链接 $snoopy->fetchform //获取表单
$formvars["username"] = "admin"; $formvars["pwd"] = "admin"; $action = "http://www.taoav.com";//表单提交地址 $snoopy->submit($action,$formvars);//$formvars为提交的数组 echo $snoopy->results; //获取表单提交后的 返回的结果 $snoopy->submittext; //提交后只返回 去除html的 文本 $snoopy->submitlinks;//提交后只返回 链接
$formvars["username"] = "admin"; $formvars["pwd"] = "admin"; $action = "http://www.taoav.com"; include "snoopy.php"; $snoopy = new Snoopy; $snoopy->cookies["PHPSESSID"] = 'fc106b1918bd522cc863f36890e6fff7'; //伪装sessionid $snoopy->agent = "(compatible; MSIE 4.01; MSN 2.5; AOL 4.0; Windows 98)"; //伪装浏览器 $snoopy->referer = "http://www.only4.cn"; //伪装来源页地址 http_referer $snoopy->rawheaders["Pragma"] = "no-cache"; //cache 的http头信息 $snoopy->rawheaders["X_FORWARDED_FOR"] = "127.0.0.101"; //伪装ip $snoopy->submit($action,$formvars); echo $snoopy->results;
$snoopy->proxy_host = "www.only4.cn"; $snoopy->proxy_port = "8080"; //使用代理 $snoopy->maxredirs = 2; //重定向次数 $snoopy->expandlinks = true; //是否补全链接 在采集的时候经常用到 // 例如链接为 /images/taoav.gif 可改为它的全链接 http://www.taoav.com/images/taoav.gif,这个地方其实可以在最后输出的时候用ereg_replace函数自己替换 $snoopy->maxframes = 5 //允许的最大框架数 //注意抓取框架的时候 $snoopy->results 返回的是一个数组 $snoopy->error //返回报错信息
<? //echo var_dump($_SERVER); include("Snoopy.class.php"); $snoopy = new Snoopy; $snoopy->agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh- CN; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5 FirePHP/0.2.1";//这项是浏览器信 息,前面你用什么浏览器查看cookie,就用那个浏览器的信息(ps:$_SERVER可以查看到浏览器的信息) $snoopy->referer = "http://bbs.phpchina.com/index.php"; $snoopy->expandlinks = true; $snoopy->rawheaders["COOKIE"]="__utmz=17229162.1227682761.29.7.utmccn=(referral)|utmcsr=phpchina.com|utmcct=/html/index.html|utmcmd=referral; cdbphpchina_smile=1D2D0D1; cdbphpchina_cookietime=2592000; __utma=233700831.1562900865.1227113506.1229613449.1231233266.16; __utmz=233700831.1231233266.16.8.utmccn=(referral)|utmcsr=localhost:8080|utmcct=/test3.php|utmcmd=referral; __utma=17229162.1877703507.1227113568.1231228465.1231233160.58; uchome_loginuser=sinopf; xscdb_cookietime=2592000; __utmc=17229162; __utmb=17229162; cdbphpchina_sid=EX5w1V; __utmc=233700831; cdbphpchina_visitedfid=17; cdbphpchinaO766uPYGK6OWZaYlvHSuzJIP22VpwEMGnPQAuWCFL9Fd6CHp2e%2FKw0x4bKz0N9lGk; xscdb_auth=8106rAyhKpQL49eMs%2FyhLBf3C6ClZ%2B2idSk4bExJwbQr%2BHSZrVKgqPOttHVr%2B6KLPg3DtWpTMUI4ttqNNVpukUj6ElM; cdbphpchina_onlineusernum=3721"; $snoopy->fetch("http://bbs.phpchina.com/forum-17-1.html"); $n=ereg_replace("href=\"","href=\"http://bbs.phpchina.com/",$snoopy->results ); echo ereg_replace("src=\"","src=\"http://bbs.phpchina.com/",$n); ?>