Snoopy.class.php下载
include "inc/Snoopy.class.php";
//读取网页,返回网页源文件内容
function read_url($str){
$snoopy = new Snoopy;
$snoopy->agent = "(compatible; MSIE 4.01; MSN 2.5; AOL 4.0; Windows 98)";
//$snoopy->agent="Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36";
$snoopy->rawheaders["Pragma"] = "no-cache";
$snoopy->maxredirs = 2;
$snoopy->offsiteok = false;
$snoopy->expandlinks = false;
if($snoopy->fetch($str))
{
$result=htmlspecialchars($snoopy->results);
}
if ($result=="")
{
if(function_exists("curl_init"))
{
if(!function_exists("lex_curl"))
{
function lex_curl($url)
{
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt ($ch, CURLOPT_TIMEOUT, 30);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt ($ch, CURLOPT_MAXREDIRS, 2);
$file_contents = curl_exec($ch);
curl_close($ch);
if($file_contents=="1") $file_contents="";
return $file_contents;
}
}
$lex_function_get="lex_curl";
}
else
{$lex_function_get="file_get_contents";}
$result=@$lex_function_get($str) or die($str.'->远程网址读取失败!');
}
return $result;
}