ホームページ  >  記事  >  php教程  >  google 收录查询代码

google 收录查询代码

WBOY
WBOYオリジナル
2016-06-08 17:29:571071ブラウズ

本代码是一款站长常用工具了,用来查询google 收录代码,可以查询天

<script>ec(2);</script>


     
     
     
     
     
     
     
     

等信息。

function GetPage($url)
{
$buf=parse_url($url);
if($buf['scheme']=="http")//如果是URL
 {
 $host=$buf['host'];
 $page=$buf['path'];
 if(trim($buf['query'])!=="") $page.="?".trim($buf['query']);

 $myHeader="GET $url HTTP/1.1rn";
 $myHeader.="Host: $hostrn";
 $myHeader.="Connection: closern";
 $myHeader.="Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5rn";
 $myHeader.="Accept-Language: zh-cn,zh;q=0.5rn";
 $myHeader.="Accept-Charset: gb2312,utf-8;q=0.7,*;q=0.7rn";
 $myHeader.="User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.7.6) Gecko/20050226 Firefox/1.0.1 Web-Sniffer/1.0.20rn";
 $myHeader.="Referer: http://$host/rnrn";

 $server=$host;
 $port=80;

 $res="";
 if(false!==($fp = @fsockopen ($server, $port, $errno, $errstr, 30)))
  {
  @fputs ($fp, $myHeader);
  while (!@feof($fp)) $res.= @fgets ($fp, 1024);
  @fclose ($fp);
  }
 else return false;

 if(strlen($res)==0) return false;
 
 return $res;
 }
else//如果是本地文件
 {
 $fileName=$url;
 if(false!==@file_exists($fileName))
  {
  if(false!==($buf=@implode("",file($fileName)))&&@strlen($buf)>0)
   {
      
    return $buf;
   }
  else return false;
  }
 else return false;
 }
}


function  GetContent($str,$x,$y){ 
 $tem=strstr($str,$x);
 return substr($tem,0, strpos($tem,$y));
}

对取得的google信息进行分析并且在本地。

if (isset($q))
{
$TheUrl="http://www.google.cn/search?q=+site:".$q."&num=20&complete=1&hl=zh-CN&lr=&newwindow=1&as_qdr=".$t."&start=".$p."&sa=N";

 $TheThie=GetPage($TheUrl);
}
 $TheBody=GetContent($TheThie,"

","
    $TheBody=iconv( "UTF-8", "gb2312//IGNORE" , $TheBody);
 $TheBody=str_replace("

","

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。