• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php知道与问问的采集插件代码_php技巧

php 搞代码 4年前 (2022-01-26) 17次浏览 已收录 0个评论

最近发现知道和问问小偷的版本越来越多了!!
看过一个百度小偷的网站也达到了pr6。收录十万多!!
在经过 荐礼啦 四十天的实践之后 发现百度对这个确实挺友好的。
从网站访问来看 很多也是从百度搜索来的!
所以用知道和问问来填充网站内容还是可行的。
于是自己开发了一个知道 问问的采集插件
原则上适合 php+mysql 并且文章是在一个表的程序
知道采集代码

 <BR><?php <BR>session_start(); <BR>header("content-type:text/html;charset=gbk"); <BR>require("stole_config.php"); <BR>require("conn.php"); <BR>require("keyword.php"); <BR>$searchStr=$_GET["searchStr"]<span>@本文来*源gaodai#ma#com搞*!代#%^码$网*</span><textarea>搞gaodaima代码</textarea>; <BR>$ss=explode(" ",$searchStr);//拆分搜索关键字 <BR>$word="";//关键字设为空 <BR>foreach($ss as $key=>$t) <BR>{ <BR>if($key>0) <BR>{ <BR>$word .="+"; <BR>} <BR>$word .=urlencode($t); <BR>} <BR>$jl=intval($_GET['jl']); <BR>if(isset($_GET['page'])) <BR>{ <BR>$page=intval($_GET['page']); <BR>}else{ <BR>$page=1; <BR>} <BR>$rs=intval($_GET['rs']); <BR>if($rs>=10) <BR>{ <BR>$rs=0; <BR>$page++; <BR>} <BR>if($page>76) <BR>{ <BR>echo "采集完毕 ${jl}"; <BR>exit(); <BR>} <BR>if(!empty($searchStr))//如果搜索 <BR>{ <BR>//获取问题页面 <BR>$content=@file_get_contents("http://zhidao.baidu.com/q?ct=17&lm=0&tn=ikaslist&pn=".(($page-1)*10)."&rn=10&word=".$word); <BR>//获取问题列表 <BR>preg_match_all("/$uid=$uid[1];//获取详细页文章 <BR>$uid=$uid[$rs]; <BR>//判断数据是否存在 <BR>$suid="bd{$uid}"; <BR>$sct=mysql_query("select count(*) from {$table_prefix}c_article where suid='$suid' "); <BR>$sct=mysql_fetch_array($sct); <BR>$sct=$sct[0]; <BR>if($sct==0) <BR>{ <BR>$content=@file_get_contents("http://zhidao.baidu.com/question/".$uid.".html") ; <BR>$arr=explode('',$content); <BR>$art_title=$arr[1]; <BR>$arr=explode('',$art_title); <BR>$art_title=$arr[0];//获取标题结束 <BR>//判断内容是否符合 <BR>$word_arr=explode(",",$cj_word); <BR>$word_allow=false;//初始化是否允许采集 <BR>$word_count=count($word_arr);//关键字总数 <BR>for($i=0;$i<$word_count;$i++) <BR>{ <BR>if(substr_count($art_title,$word_arr[$i])>0) <BR>{ <BR>$word_allow=1; <BR>$i=$word_count; <BR>} <BR>} <BR>if($word_allow)//如果满足条件 <BR>{ <BR>$arr=explode('<pre class="prettyprint linenums">',$content); <BR>$contentQuestion=$arr[1]; <BR>$arr=explode('

‘,$contentQuestion);
$contentQuestion=$arr[0];
echo “开始采集内容
“;
echo “$art_title
“;
@preg_match_all(‘/(|)

(.*)<\/pre>(<\/ca>|<\/cn>)/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('<pre class="prettyprint linenums">','',$t); <BR>$answerTemp=str_replace('

‘,”,$answerTemp);
$answerTemp=str_replace(‘

','',$answerTemp); <BR>$answerTemp=str_replace('

‘,”,$answerTemp);
if(strlen($answerTemp)>$min_t1)
{
$art_content .=$answerTemp.”
“;
}
}
//去除链接
$s1=”/()(.*)<\/a>/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();
}
?>
<link href=”style.css” rel=”stylesheet” type=”text/css” />





荐礼啦知道问问采集插件






采集设置 卸载采集 查看采集记录 采集帮助 知道采集 问问采集






问问采集代码:

 <BR><?php <BR>session_start(); <BR>header("content-type:text/html;charset=utf-8"); <BR>require("stole_config.php"); <BR>require("conn.php"); <BR>require("keyword.php"); <BR>if(!empty($_POST['ask'])) <BR>{ <BR>$ask=urlencode(trim($_POST['ask']));//获取表单提交的问题 <BR>$sp="S".$ask; <BR>}else <BR>{ <BR>$sp=urlencode($_GET['sp']); <BR>} <BR>if(empty($_GET['jl'])) <BR>{ <BR>$_GET['jl']=1; <BR>} <BR>$jl=$_GET['jl']; <BR>$pg=intval($_GET['pg']);//获取页数 <BR>$rs=intval($_GET['rs']);//获得 记录的参数 <BR>if($rs>9) <BR>{ <BR>$rs=0; <BR>$pg++; <BR>} <BR>if($pg>51) <BR>{ <BR>echo "采集完毕! 总共采集 ".urldecode($sp)." ".$jl."条记录"; <BR>exit(); <BR>} <BR>if($sp)//有设定答案才开始 <BR>{ <BR>$str=@file_get_contents("http://wenwen.soso.com/z/Search.e?sp={$sp}&pg={$pg}"); <BR>@preg_match("/<ol class="result_list">(.*)<\/ol>/iUs",$str,$asklist);//获取问答列表 <BR>//echo $asklist[1]; <BR>$url="/@preg_match_all($url,$asklist[1],$urllist);//获取 所有的问题 <BR>$t=$urllist[1][$rs]; <BR>$uid=$t; <BR>$suid="ww{$uid}"; <BR>$sct=mysql_query("select count(*) from {$table_prefix}c_article where suid='$suid' "); <BR>$sct=mysql_fetch_array($sct); <BR>$sct=$sct[0]; <BR>if($sct==0) <BR>{ <BR>$html=@file_get_contents("http://wenwen.soso.com/z/${t}"); <BR>$html=str_replace("<pre class="prettyprint linenums">","",str_replace("

“,””,$html));
$html=str_replace(“

“,”

“,$html);
//echo $html;
@preg_match(“/

.*

(.*)<\/h3>/iUs”,$html,$ask_title);
$art_title=$ask_title[1];
@preg_match(“/

(.*)<\/div>/iUs”,$html,$answer);
$j=count($answer)-1;
$art_content=””;//商品详细
for($i=$j;$i>=1;$i–)
{
if(strlen($answer[$i])>$min_t1)
{
$art_content .= $answer[$i];
}
}
$art_content=trim($art_content);
$s1=”/()(.*)<\/a>/iUs”;
$art_content=preg_replace($s1,${2},trim($art_content));
$word_arr=explode(“,”,iconv(“gbk”,”utf-8″,$cj_word));
$word_allow=false;//初始化是否允许采集
$word_count=count($word_arr);//总数
for($i=0;$i<$word_count;$i++)
{
if(substr_count($art_title,$word_arr[$i])>0)
{
$word_allow=1;
$i=$word_count;
}
}
if($word_allow)//如果合法
{ //开始处理数据库
if(strlen($art_content)>$min_t2)
{
echo “添加中……………………….
“;
echo $art_title.”
“;
$art_title=iconv(‘utf-8′,’gbk’, $art_title);
$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_content=iconv(‘utf-8′,’gbk’,str_replace(“\r\n”,”
“,$art_content));
$art_content=strtr($art_content,$keyword);
$art_time=date(“Y-m-d”);
$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++;//如果存放数据库中 则记录加1
//处理数据库结束
}else
{
echo “长度不够”;
}
}else
{
echo “主题不符合要求”;
}
}else
{
echo “已经存在”;
}
$rs++;
//记录下本次采集 的状况
$f_tt= urldecode($sp).”–页数”.$pg.” 记录数 “.$jl ;
file_put_contents(“ss.txt”,$f_tt);
echo “<script>location.href=’wenwen.php?jl=”.$jl.”&sp=”.$sp.”&pg=”.$pg.”&rs=”.$rs.” ‘;</script>”;
exit();
}
?>
<link href=”style.css” rel=”stylesheet” type=”text/css” />





荐礼啦知道问问采集插件






采集设置 卸载采集 查看采集记录 采集帮助 知道采集 问问采集











搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php知道与问问的采集插件代码_php技巧

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址