首页 > 开发 > PHP > 正文

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

2024-05-04 22:08:31
字体:
来源:转载
供稿:网友
最近发现知道和问问小偷的版本越来越多了!!
看过一个百度小偷的网站也达到了pr6。收录十万多!!
在经过 荐礼啦 四十天的实践之后 发现百度对这个确实挺友好的。
从网站访问来看 很多也是从百度搜索来的!
所以用知道和问问来填充网站内容还是可行的。
于是自己开发了一个知道 问问的采集插件
原则上适合 php+mysql 并且文章是在一个表的程序
知道采集代码
代码如下:
<?php
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("/<a href=/"//question//(.*)/.html/iUs",$content,$uid);
$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('<cq>',$content);
$art_title=$arr[1];
$arr=explode('</cq>',$art_title);
$art_title=$arr[0];//获取标题结束
//判断内容是否符合
$word_arr=explode(",",$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)//如果满足条件
{
$arr=explode('<cd><pre>',$content);
$contentQuestion=$arr[1];
$arr=explode('</pre></cd>',$contentQuestion);
$contentQuestion=$arr[0];
echo "开始采集内容<br>";
echo "$art_title<br>";
@preg_match_all('/(<ca>|<cn>)<pre>(.*)<//pre>(<//ca>|<//cn>)/iUs',$content,$answerArr);
$answerArr=$answerArr[2];
if($arr_order==1)//随机排序
{
shuffle($answerArr);
}
if($arr_order==2)//倒序
{
$answerArr=krsort($answerArr);//倒序
}
foreach($answerArr as $t)
{
$answerTemp=str_replace('<ca><pre>','',$t);
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表