<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<?php
include("conn.php");
$date=date("Y-m-d");
$sql="select url,url from url";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query)){
$url=$row["url"];
$id=$row["id"];
// echo $url;
$url=str_replace("http://","",$url);
//echo $url;
//exit;
$url="http://www.baidu.com/s?ie=gb2312&bs=site%3A".$url."%2Fqbs%2F&sr=&z=&cl=3&f=8&wd=site%3A".$url."&ct=0";
//echo $url;
$lines_array = file($url);
//print_r($lines_array);
$keyword=$lines_array[79];
//echo $keyword;
$pos1=strpos($keyword,"约");
//echo "pos1:".$pos1."<br/>";
$pos2=strpos($keyword,"篇");
//echo "pos2:".$pos2."<br/>";
$pos3=strpos($keyword,"页");
//echo "pos3:".$pos3."<br/>";
if($pos1!=""&&$pos2!=""){
$num=substr($keyword,$pos1+2,$pos2-$pos1-2);
}elseif($pos2!=""&&$pos3!=""){
$num=substr($keyword,$pos3+2,$pos2-$pos3-2);
}else{
$num="0";
}
//echo $num;
//echo "<br/>";
$sq="select * from shoulu where id=".$id." and searchengine='baidu' and date='".$date."'";
//echo $sq;
$result=mysql_query($sq);
$flag=mysql_num_rows($result);
if($flag!=0){
//echo "oh";
}elseif($flag==0){
if($num!="0"){
$new="insert into shoulu(id,num,searchengine,date) values(".$id.",'".$num."','baidu',now())";
mysql_query($new,$db);
}
}
}
?>
<script language=javascript>
alert("统计成功");
window.close();
window.opener.location.href='web_list.php?searchengine=baidu'
</script>
</body>
</html>