//php处理代码
function get_microtime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
$time_start = get_microtime();
set_time_limit(0);
$kw=$_GET["kw"];
$url=$_GET["url"];
$depth=$_GET["depth"];
$next=1;$pn=0;$flag=0;$n=1;$ps教程=0;
$baseurl="http://www.baidu.com/s?";
$kw=str_replace("+","%2B",$kw);
$kw=str_replace(" ","%20",$kw);
if($depth==""||$depth<=0) $depth=10;
if($depth>76) $depth=76;
echo "
while($next==1)
{
$baidu_url=$baseurl."lm=0&si=&rn=10&tn=wangcong&ie=gb2312&ct=0&wd=".$kw."&pn=".$pn."&cl=3";
$str=file_get_contents($baidu_url);
$baidu_url=str_replace("%20","+",$baidu_url);
if(strpos($str,$url))
{
if($n==1) echo "在百度中查找关键字:'".$kw."',来自'".$url."'的结果有:
";
$pagenum=$pn/10+1;
echo "
第".$n."条结果, ";
echo "在百度搜索结果中排在第".$pagenum."页";
echo "
";
echo " 点此查看";
echo "
";
$flag=1;
$n=$n+1;
}
$pn=$pn+10;
$ps=$ps+1;
if($ps==$depth) $next=0;
if(!strpos($str,"下一页")) $next=0; //判断有没有下一页;
}
$time_end = get_microtime();
$time = $time_end - $time_start;
if($flag==0) echo "
在当前的深度条件下没有找到来自 ".$url." 的结果,您的忧化还有待进步,您可以尝试加大查询深度.
";
$n=$n-1;
echo "
统计信息:一共找了".$ps."页,找到".$n."条相关结果,耗时:".$time."秒.
";
?>