最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2010年10月12日 09:39:59   作者:  
看過一個百度小偷的網(wǎng)站也達(dá)到了pr6。收錄十萬多??! 在經(jīng)過 薦禮啦 四十天的實踐之后 發(fā)現(xiàn)百度對這個確實挺友好的。
最近發(fā)現(xiàn)知道和問問小偷的版本越來越多了??!
看過一個百度小偷的網(wǎng)站也達(dá)到了pr6。收錄十萬多??!
在經(jīng)過 薦禮啦 四十天的實踐之后 發(fā)現(xiàn)百度對這個確實挺友好的。
從網(wǎng)站訪問來看 很多也是從百度搜索來的!
所以用知道和問問來填充網(wǎng)站內(nèi)容還是可行的。
于是自己開發(fā)了一個知道 問問的采集插件
原則上適合 php+mysql 并且文章是在一個表的程序
知道采集代碼
復(fù)制代碼 代碼如下:

<?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);//拆分搜索關(guān)鍵字
$word="";//關(guān)鍵字設(shè)為空
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];//獲取詳細(xì)頁文章
$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];//獲取標(biāo)題結(jié)束
//判斷內(nèi)容是否符合
$word_arr=explode(",",$cj_word);
$word_allow=false;//初始化是否允許采集
$word_count=count($word_arr);//關(guān)鍵字總數(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 "開始采集內(nèi)容<br>";
echo "$art_title<br>";
@preg_match_all('/(<ca>|<cn>)<pre>(.*)<\/pre>(<\/ca>|<\/cn>)/iUs',$content,$answerArr);
$answerArr=$answerArr[2];
if($arr_order==1)//隨機(jī)排序
{
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' ");//查看標(biāo)題是否重復(fù)
$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 "內(nèi)容長度不夠";
}
//獲取文章內(nèi)容結(jié)束
}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">采集設(shè)置</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>

問問采集代碼:
復(fù)制代碼 代碼如下:

<?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)//有設(shè)定答案才開始
{
$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="";//商品詳細(xì)
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' ");//查看標(biāo)題是否重復(fù)
$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ù)庫結(jié)束
}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">采集設(shè)置</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>

相關(guān)文章

  • php比較多維數(shù)組中值的大小排序?qū)崿F(xiàn)代碼

    php比較多維數(shù)組中值的大小排序?qū)崿F(xiàn)代碼

    php中根據(jù)數(shù)組的鍵(key)進(jìn)行比較,排序,有很多內(nèi)置函數(shù)可以輕松解決,如krsort(), ksort()等。如果是根據(jù)數(shù)組的值(value)進(jìn)行比較就麻煩一些
    2012-09-09
  • PHP實現(xiàn)網(wǎng)站應(yīng)用微信登錄功能詳解

    PHP實現(xiàn)網(wǎng)站應(yīng)用微信登錄功能詳解

    這篇文章主要介紹了PHP實現(xiàn)網(wǎng)站應(yīng)用微信登錄功能,結(jié)合實例形式詳細(xì)分析了php實現(xiàn)微信授權(quán)登錄功能的具體操作步驟與相關(guān)實現(xiàn)技巧,需要的朋友可以參考下
    2019-04-04
  • php使用cookie顯示用戶上次訪問網(wǎng)站日期的方法

    php使用cookie顯示用戶上次訪問網(wǎng)站日期的方法

    這篇文章主要介紹了php使用cookie顯示用戶上次訪問網(wǎng)站日期的方法,主要通過使用cookie保存訪問時間來實現(xiàn)該功能,需要的朋友可以參考下
    2015-01-01
  • PHP中session使用方法詳解

    PHP中session使用方法詳解

    在PHP開發(fā)中對比起Cookie,session 是存儲在服務(wù)器端的會話,相對安全,并且不像 Cookie 那樣有存儲長度限制,本文簡單介紹 session 的使用
    2007-03-03
  • php實現(xiàn)倒計時效果

    php實現(xiàn)倒計時效果

    這篇文章主要介紹了php實現(xiàn)倒計時效果,寫了一個考試系統(tǒng)剩余時間倒計時的顯示代碼和大家一起探討,需要的朋友可以參考下
    2015-12-12
  • PHP的單引號和雙引號 字符串效率

    PHP的單引號和雙引號 字符串效率

    經(jīng)常有人問我,聽說在PHP中處理字符串用單引號會快,那么如果存在變量替換的時候,是使用單引號連接快呢,還是雙引號快呢?
    2009-05-05
  • php中通過DirectoryIterator刪除整個目錄的方法

    php中通過DirectoryIterator刪除整個目錄的方法

    這篇文章主要介紹了php中通過DirectoryIterator刪除整個目錄的方法,實例分析了php通過DirectoryIterator類操作目錄的技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-03-03
  • phpstudy無法啟動MySQL服務(wù)的解決方法

    phpstudy無法啟動MySQL服務(wù)的解決方法

    個人比較懶,所以想到用phpstudy這個軟件進(jìn)行控制,但這個時候問題出現(xiàn)了:在下載phpstudy后想要啟動MySQL服務(wù),但是總是無法啟動,所以本文給大家介紹了如何解決phpstudy無法啟動MySQL服務(wù)的問題,需要的朋友可以參考下
    2024-06-06
  • 解析php中array_merge與array+array的區(qū)別

    解析php中array_merge與array+array的區(qū)別

    本篇文章是對php中array_merge與array+array的區(qū)別進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-06-06
  • Windows2003下php5.4安裝配置教程(IIS)

    Windows2003下php5.4安裝配置教程(IIS)

    這篇文章主要為大家詳細(xì)介紹了在Windows2003下IIS與php5.4配置教程,感興趣的小伙伴們可以參考一下
    2016-06-06

最新評論

六盘水市| 建阳市| 木兰县| 普宁市| 安吉县| 淳安县| 康乐县| 伽师县| 肥西县| 交口县| 炎陵县| 昆山市| 黎城县| 龙江县| 资中县| 耒阳市| 太保市| 香河县| 丰原市| 高平市| 南岸区| 辽宁省| 葫芦岛市| 西畴县| 固原市| 阿拉善右旗| 鄂托克前旗| 娄底市| 金山区| 房山区| 罗城| 利津县| 泗洪县| 寻乌县| 古交市| 奈曼旗| 和林格尔县| 阆中市| 崇信县| 额济纳旗| 安远县|