php中Snoopy类用法实例
本文实例讲述了php中Snoopy类用法。分享给大家供大家参考。具体分析如下:
这里演示了php中如何通过Snoopy抓取网页信息
snoopy类的下载地址:http://sourceforge.net/projects/snoopy/
/* Youneedthesnoopy.class.phpfrom http://snoopy.sourceforge.net/ */ include("snoopy.class.php"); $snoopy=newSnoopy; //needanproxy?: //$snoopy->proxy_host="my.proxy.host"; //$snoopy->proxy_port="8080"; //setbrowserandreferer: $snoopy->agent="Mozilla/4.0(compatible;MSIE6.0;WindowsNT5.1)"; $snoopy->referer="http://www.jonasjohn.de/"; //setsomecookies: $snoopy->cookies["SessionID"]='238472834723489'; $snoopy->cookies["favoriteColor"]="blue"; //setanraw-header: $snoopy->rawheaders["Pragma"]="no-cache"; //setsomeinternalvariables: $snoopy->maxredirs=2; $snoopy->offsiteok=false; $snoopy->expandlinks=false; //setusernameandpassword(optional) //$snoopy->user="joe"; //$snoopy->pass="bloe"; //fetchthetextofthewebsitewww.google.com: if($snoopy->fetchtext("http://www.google.com")){ //othermethods:fetch,fetchform,fetchlinks,submittextandsubmitlinks //responsecode: print"responsecode:".$snoopy->response_code."<br/>\n"; //printtheheaders: print"<b>Headers:</b><br/>"; while(list($key,$val)=each($snoopy->headers)){ print$key.":".$val."<br/>\n"; } print"<br/>\n"; //printthetextsofthewebsite: print"<pre>".htmlspecialchars($snoopy->results)."</pre>\n"; } else{ print"Snoopy:errorwhilefetchingdocument:".$snoopy->error."\n"; }
希望本文所述对大家的php程序设计有所帮助。