session_start();
header("content-type:text/html;charset=gbk");
require("stole_config.php");
require("conn.php");
require("keyword.php");
$searchStr=$_GET["searchStr"];
$ss=explode(" ",$searchStr);//拆分搜索关键字
$word="";//关键字设为空
foreach($ss as $key=>$t)
{
if($key>0)
{
$word .="+";
}
$word .=urlencode($t);
}
$jl=intval($_GET['jl']);
if(isset($_GET['page']))
{
$page=intval($_GET['page']);
}else{
$page=1;
}
$rs=intval($_GET['rs']);
if($rs>=10)
{
$rs=0;
$page++;
}
if($page>76)
{
echo "采集完毕 ${jl}";
exit();
}
if(!empty($searchStr))//如果搜索
{
//获取问题页面
$content=@file_get_contents("http://zhidao.baidu.com/q?ct=17&lm=0&tn=ikaslist&pn=".(($page-1)*10)."&rn=10&word=".$word);
//获取问题列表
preg_match_all("/
$uid=$uid[1];//获取详细页文章
$uid=$uid[$rs];
//判断数据是否存在
$suid="bd{$uid}";
$sct=mysql_query("select count(*) from {$table_prefix}c_article where suid='$suid' ");
$sct=mysql_fetch_array($sct);
$sct=$sct[0];
if($sct==0)
{
$content=@file_get_contents("http://zhidao.baidu.com/question/".$uid.".html") ;
$arr=explode('',$content);
$art_title=$arr[1];
$arr=explode('',$art_title);
$art_title=$arr[0];//获取标题结束
//判断内容是否符合
$word_arr=explode(",",$cj_word);
$word_allow=false;//初始化是否允许采集
$word_count=count($word_arr);//关键字总数
for($i=0;$i{
if(substr_count($art_title,$word_arr[$i])>0)
{
$word_allow=1;
$i=$word_count;
}
}
if($word_allow)//如果满足条件
{
$arr=explode('',$content); <br>$contentQuestion=$arr[1]; <br>$arr=explode('
',$contentQuestion);
$contentQuestion=$arr[0];
echo "开始采集内容
";
echo "$art_title
";
@preg_match_all('/(|)(.*)(|)/iUs',$content,$answerArr); <br>$answerArr=$answerArr[2]; <br>if($arr_order==1)//随机排序 <br>{ <br>shuffle($answerArr); <br>} <br>if($arr_order==2)//倒序 <br>{ <br>$answerArr=krsort($answerArr);//倒序 <br>} <br>foreach($answerArr as $t) <br>{ <br>$answerTemp=str_replace('<ca><pre class="brush:php;toolbar:false">','',$t); <br>$answerTemp=str_replace('
','',$answerTemp); <br>$answerTemp=str_replace('','',$answerTemp); <br>$answerTemp=str_replace('
','',$answerTemp);
if(strlen($answerTemp)>$min_t1)
{
$art_content .=$answerTemp."
";
}
}
//去除链接
$s1="/()(.*)/iUs";
$art_content=preg_replace($s1,${2},trim($art_content));
$art_content=str_replace("\n\r","
",$art_content);
if(strlen($art_content)>$min_t2)
{
$title_ct=mysql_query("select count(*) from {$table_prefix}c_article where art_title ='$art_title' ");//查看标题是否重复
$title_ct=@mysql_fetch_array($title_ct);
$title_ct=$title_ct[0];
if($title_ct>0)
{
$art_title .="{$same_title}{$title_ct}";
}
$art_time=date("Y-m-d");
$art_content=strtr($art_content,$keyword);
$sql="insert into {$table_prefix}c_article(art_title,art_content,art_time,art_author,suid) values('$art_title','$art_content','$art_time','$art_author','$suid')";//插入采集表
mysql_query($sql);
if(empty($t_catx_id))//如果无分类
{
$sql2="insert into {$t_table}({$t_art_title},{$t_art_content},{$t_art_time},{$t_artx_author}) values('$art_title','$art_content','$art_time','$art_author')";
}else
{
$sql2="insert into {$t_table}({$t_art_title},{$t_art_content},{$t_art_time},{$t_artx_author},{$t_catx_id}) values('$art_title','$art_content','$art_time','$art_author','$cat_id')";
}
mysql_query($sql2);//插入文章表
$jl++;
//数据库处理完毕
}else
{
echo "内容长度不够";
}
//获取文章内容结束
}else
{
echo "主题不符合要求";
}
}else
{
echo "已经存在";
}$rs++;
file_put_contents("bd.txt","采集{$searchStr}到第{$page}第{$rs}条");
echo "<script>location.href='baidu.php?searchStr=".urlencode($searchStr)."&page=".$page."&rs=".$rs."&jl=".$jl." ';</script>";
exit();
}
?>