欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php知道與問問的采集插件代碼

 更新時間:2010年10月12日 09:39:59   作者:  
看過一個百度小偷的網(wǎng)站也達到了pr6。收錄十萬多!! 在經(jīng)過 薦禮啦 四十天的實踐之后 發(fā)現(xiàn)百度對這個確實挺友好的。
最近發(fā)現(xiàn)知道和問問小偷的版本越來越多了?。?
看過一個百度小偷的網(wǎng)站也達到了pr6。收錄十萬多!!
在經(jīng)過 薦禮啦 四十天的實踐之后 發(fā)現(xiàn)百度對這個確實挺友好的。
從網(wǎng)站訪問來看 很多也是從百度搜索來的!
所以用知道和問問來填充網(wǎng)站內容還是可行的。
于是自己開發(fā)了一個知道 問問的采集插件
原則上適合 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];
//判斷數(shù)據(jù)是否存在
$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);//關鍵字總數(shù)
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);
$answerTemp=str_replace('</pre></ca>','',$answerTemp);
$answerTemp=str_replace('<cn><pre>','',$answerTemp);
$answerTemp=str_replace('</pre></cn>','',$answerTemp);
if(strlen($answerTemp)>$min_t1)
{
$art_content .=$answerTemp."<br>";
}
}
//去除鏈接
$s1="/(<a .*>)(.*)<\/a>/iUs";
$art_content=preg_replace($s1,${2},trim($art_content));
$art_content=str_replace("\n\r","<br>",$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++;
//數(shù)據(jù)庫處理完畢
}else
{
echo "內容長度不夠";
}
//獲取文章內容結束
}else
{
echo "主題不符合要求";
}
}else
{
echo "已經(jīng)存在";
}$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" />
<table width="700" border="0" align="center" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td height="50" align="center" bgcolor="#00CC00"><h1><a >薦禮啦</a>知道問問采集插件</h1></td>
</tr>
</table>
<table width="700" border="0" align="center" cellspacing="1" bgcolor="#CCCCCC" style="margin-top:6px; margin-bottom:6px;">
<tr>
<td height="30" align="center" bgcolor="#FFFFFF"><a href="cj_config.php">采集設置</a> <a href="uninstall.php" onclick="return confirm('您確定要卸載采集插件嗎');">卸載采集</a>&nbsp;<a href="cj_view.php">查看采集記錄</a>&nbsp;<a href="cj_help.php">采集幫助</a> <a href="baidu.php" target="_blank">知道采集</a> &nbsp;<a href="wenwen.php" target="_blank">問問采集</a></td>
</tr>
</table>
<table width="537" height="45" align="center" style="margin-top:30px;"><tr><td height="39">
<form id="form1" name="form1" method="get" action="baidu.php">
<div id="search">
<input name="searchStr" type="text" id="searchStr" value="<?php echo $searchStr; ?>" size="60" />
<input type="submit" name="searchBtn" id="searchBtn" value="知道偷偷" style="height:25px; line-height:25px;" />
</div>
</form>
</td></tr></table>

問問采集代碼:
復制代碼 代碼如下:

<?php
session_start();
header("content-type:text/html;charset=utf-8");
require("stole_config.php");
require("conn.php");
require("keyword.php");
if(!empty($_POST['ask']))
{
$ask=urlencode(trim($_POST['ask']));//獲取表單提交的問題
$sp="S".$ask;
}else
{
$sp=urlencode($_GET['sp']);
}
if(empty($_GET['jl']))
{
$_GET['jl']=1;
}
$jl=$_GET['jl'];
$pg=intval($_GET['pg']);//獲取頁數(shù)
$rs=intval($_GET['rs']);//獲得 記錄的參數(shù)
if($rs>9)
{
$rs=0;
$pg++;
}
if($pg>51)
{
echo "采集完畢! 總共采集 ".urldecode($sp)." ".$jl."條記錄";
exit();
}
if($sp)//有設定答案才開始
{
$str=@file_get_contents("http://wenwen.soso.com/z/Search.e?sp={$sp}&pg={$pg}");
@preg_match("/<ol class=\"result_list\">(.*)<\/ol>/iUs",$str,$asklist);//獲取問答列表
//echo $asklist[1];
$url="/<a target=\"_blank\" href=\"\/z\/(q.*\.htm)/iUs";
@preg_match_all($url,$asklist[1],$urllist);//獲取 所有的問題
$t=$urllist[1][$rs];
$uid=$t;
$suid="ww{$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)
{
$html=@file_get_contents("http://wenwen.soso.com/z/${t}");
$html=str_replace("<pre>","",str_replace("</pre>","",$html));
$html=str_replace("<br/><br/><br/>","<br/><br/>",$html);
//echo $html;
@preg_match("/<div class=\"question_main\">.*<h3>(.*)<\/h3>/iUs",$html,$ask_title);
$art_title=$ask_title[1];
@preg_match("/<div class=\"answer_con\">(.*)<\/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 .*>)(.*)<\/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);//總數(shù)
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)//如果合法
{ //開始處理數(shù)據(jù)庫
if(strlen($art_content)>$min_t2)
{
echo "<font color=red>添加中............................</font><br>";
echo $art_title."<br>";
$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","<br>",$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++;//如果存放數(shù)據(jù)庫中 則記錄加1
//處理數(shù)據(jù)庫結束
}else
{
echo "長度不夠";
}
}else
{
echo "主題不符合要求";
}
}else
{
echo "已經(jīng)存在";
}
$rs++;
//記錄下本次采集 的狀況
$f_tt= urldecode($sp)."--頁數(shù)".$pg." 記錄數(shù) ".$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" />
<table width="700" border="0" align="center" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td height="50" align="center" bgcolor="#00CC00"><h1><a >薦禮啦</a>知道問問采集插件</h1></td>
</tr>
</table>
<table width="700" border="0" align="center" cellspacing="1" bgcolor="#CCCCCC" style="margin-top:6px; margin-bottom:6px;">
<tr>
<td height="30" align="center" bgcolor="#FFFFFF"><a href="cj_config.php">采集設置</a> <a href="uninstall.php" onclick="return confirm('您確定要卸載采集插件嗎');">卸載采集</a>&nbsp;<a href="cj_view.php">查看采集記錄</a>&nbsp;<a href="cj_help.php">采集幫助</a> <a href="baidu.php" target="_blank">知道采集</a> &nbsp;<a href="wenwen.php" target="_blank">問問采集</a></td>
</tr>
</table>
<form action="wenwen.php" method="post">
<table width="628" height="49" border="0" align="center">
<tr>
<td width="413" align="right"><input name="ask" type="text" id="ask" size="50"></td>
<td width="205"><input type="submit" name="button" id="button" value="問問采集" style=" padding-left:15px; padding-right:15px; height:25px; line-height:25px;"></td>
</tr>
</table>
</form>

相關文章

  • 解決PHP4.0 和 PHP5.0類構造函數(shù)的兼容問題

    解決PHP4.0 和 PHP5.0類構造函數(shù)的兼容問題

    以下是對解決PHP4.0和PHP5.0類構造函數(shù)兼容問題的方法進行了詳細的分析介紹,需要的朋友可以過來參考一下
    2013-08-08
  • 利用php操作memcache緩存的基礎方法示例

    利用php操作memcache緩存的基礎方法示例

    Memcache函數(shù)庫是在PECL(PHP Extension Community Library)中,主要作用是搭建大容量的內存數(shù)據(jù)的臨時存放區(qū)域,在分布式的時候作用體現(xiàn)的非常明顯,否則不建議使用。本文將給大家介紹了關于利用php操作memcache緩存的基礎方法,需要的朋友可以參考下。
    2017-08-08
  • PHP獲取數(shù)組中重復最多的元素的實現(xiàn)方法

    PHP獲取數(shù)組中重復最多的元素的實現(xiàn)方法

    這篇文章主要介紹了PHP獲取數(shù)組中重復最多的元素的實現(xiàn)方法,通過一個自定義函數(shù)遍歷數(shù)組實現(xiàn)這一功能,是非常使用的技巧,需要的朋友可以參考下
    2014-11-11
  • PHP迭代器和生成器用法實例分析

    PHP迭代器和生成器用法實例分析

    這篇文章主要介紹了PHP迭代器和生成器用法,結合實例形式分析了PHP迭代器和生成器的相關概念、原理、應用技巧與使用注意事項,需要的朋友可以參考下
    2019-09-09
  • PHP互換兩個變量值的方法(不用第三變量)

    PHP互換兩個變量值的方法(不用第三變量)

    相信每個剛接觸PHP語言的童鞋們應該藕知道,PHP中兩個變量的值互換是個很常見的做法,那么下面這篇文章我們就來介紹幾個對于變量值互換的常見操作方法,文中介紹的很詳細,相信對于大家的理解和學習很有幫助,下面有需要的朋友們來一起看看吧。
    2016-11-11
  • PHP模塊 Memcached功能多于Memcache

    PHP模塊 Memcached功能多于Memcache

    PHP搭配Memcached已經(jīng)是婦孺皆知的標配了。再提似乎讓人覺得太“圡”了,不過有一些細節(jié)不見得人人都清楚
    2011-06-06
  • 用PHP的ob_start() 控制您的瀏覽器cache

    用PHP的ob_start() 控制您的瀏覽器cache

    Output Control 函數(shù)可以讓你自由控制腳本中數(shù)據(jù)的輸出。它非常地有用,特別是對于:當你想在數(shù)據(jù)已經(jīng)輸出后,再輸出文件頭的情況。
    2009-08-08
  • php中mysql操作buffer用法詳解

    php中mysql操作buffer用法詳解

    這篇文章主要介紹了php中mysql操作buffer用法,以實例形式較為詳細的分析了mysql操作buffer的技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-03-03
  • PHP 和 MySQL 開發(fā)的 8 個技巧

    PHP 和 MySQL 開發(fā)的 8 個技巧

    PHP 和 MySQL 開發(fā)的 8 個技巧...
    2007-01-01
  • PHP寫日志的實現(xiàn)方法

    PHP寫日志的實現(xiàn)方法

    這篇文章主要介紹了PHP寫日志的實現(xiàn)方法,是PHP程序設計中比較實用的技巧,需要的朋友可以參考下
    2014-11-11

最新評論