国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

php 問問采集代碼

2024-05-04 21:48:54
字體:
來源:轉載
供稿:網友

提供一款免費的php 問問采集代碼,如果你正想采集問問,但是又不知道怎么寫采集程序,這里為你提供一款經典的問問采集程序,代碼如下:

  1. <?php  
  2. session_start();  
  3. header("content-type:text/html;charset=utf-8");  
  4. require("stole_config.php");  
  5. require("conn.php");  
  6. require("keyword.php");  
  7. if(!emptyempty($_post['ask']))  
  8. {  
  9. $ask=urlencode(trim($_post['ask']));//獲取表單提交的問題  
  10. $sp="s".$ask;  
  11. }else  
  12. {  
  13. $sp=urlencode($_get['sp']);  
  14. }  
  15. if(emptyempty($_get['jl']))  
  16. {  
  17. $_get['jl']=1;  
  18. }  
  19. $jl=$_get['jl'];  
  20. $pg=intval($_get['pg']);//獲取頁數  
  21. $rs=intval($_get['rs']);//獲得 記錄的參數  
  22. if($rs>9)  
  23. {  
  24. $rs=0;  
  25. $pg++;  
  26. }  
  27. if($pg>51)  
  28. {  
  29. echo "采集完畢! 總共采集 ".urldecode($sp)." ".$jl."條記錄";  
  30. exit();  
  31. }  
  32. if($sp)//有設定答案才開始  
  33. {  
  34. $str=@file_get_contents("http://wenwen.soso.com/z/search.e?sp={$sp}&pg={$pg}");  
  35. @preg_match("/<ol class="result_list">(.*)</ol>/ius",$str,$asklist);//獲取問答列表  
  36. //echo $asklist[1];  
  37. $url="/<a target="_blank" href="/z/(q.*.htm)/ius";  
  38. @preg_match_all($url,$asklist[1],$urllist);//獲取 所有的問題  
  39. $t=$urllist[1][$rs];  
  40. $uid=$t;  
  41. $suid="ww{$uid}";  
  42. $sct=mysql教程_query("select count(*) from {$table_prefix}c_article where suid='$suid' ");  
  43. $sct=mysql_fetch_array($sct);  
  44. $sct=$sct[0];  
  45. if($sct==0)  
  46. {  
  47. $html=@file_get_contents("http://wenwen.soso.com/z/${t}");  
  48. $html=str_replace("<pre>","",str_replace("</pre>","",$html));  
  49. $html=str_replace("<br/><br/><br/>","<br/><br/>",$html);  
  50. //echo $html;  
  51. @preg_match("/<div class="question_main">.*<h3>(.*)</h3>/ius",$html,$ask_title);  
  52. $art_title=$ask_title[1];  
  53. @preg_match("/<div class="answer_con">(.*)</div>/ius",$html,$answer);  
  54. $j=count($answer)-1;  
  55. $art_content="";//商品詳細  
  56. for($i=$j;$i>=1;$i--)  
  57. {  
  58. if(strlen($answer[$i])>$min_t1)  
  59. {  
  60. $art_content .= $answer[$i];  
  61. }  
  62. }  
  63. $art_content=trim($art_content);  
  64. $s1="/(<a .*>)(.*)</a>/ius";  
  65. $art_content=preg_replace($s1,${2},trim($art_content));  
  66. $word_arr=explode(",",iconv("gbk","utf-8",$cj_word));  
  67. $word_allow=false;//初始化是否允許采集  
  68. $word_count=count($word_arr);//總數  
  69. for($i=0;$i<$word_count;$i++)  
  70. {  
  71. if(substr_count($art_title,$word_arr[$i])>0)  
  72. {  
  73. $word_allow=1;  
  74. $i=$word_count;  
  75. }  
  76. }  
  77. if($word_allow)//如果合法  
  78. //開始處理數據庫教程  
  79. if(strlen($art_content)>$min_t2)  
  80. {  
  81. echo "<font color=red>添加中............................</font><br>";  
  82. echo $art_title."<br>";  
  83. $art_title=iconv('utf-8','gbk'$art_title);  
  84. $title_ct=mysql_query("select count(*) from {$table_prefix}c_article where art_title ='$art_title' ");//查看標題是否重復  
  85. $title_ct=@mysql_fetch_array($title_ct);  
  86. $title_ct=$title_ct[0];  
  87. if($title_ct>0)  
  88. {  
  89. $art_title .="{$same_title}{$title_ct}";  
  90. }  
  91. $art_content=iconv('utf-8','gbk',str_replace(" ","<br>",$art_content));  
  92. $art_content=strtr($art_content,$keyword);  
  93. $art_time=date("y-m-d");  
  94. $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')";//插入采集表  
  95. mysql_query($sql);  
  96. if(emptyempty($t_catx_id))//如果無分類  
  97. {  
  98. $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')";  
  99. }else  
  100. {  
  101. $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')";  
  102. }  
  103. mysql_query($sql2);//插入文章表  
  104. $jl++;//如果存放數據庫中 則記錄加1  
  105. //處理數據庫結束  
  106. }else  
  107. {  
  108. echo "長度不夠";  
  109. }  
  110. }else  
  111. {  
  112. echo "主題不符合要求";  
  113. }  
  114. }else  
  115. {  
  116. echo "已經存在";  
  117. }  
  118. $rs++;  
  119. //記錄下本次采集 的狀況  
  120. $f_tt= urldecode($sp)."--頁數".$pg." 記錄數 ".$jl ;  
  121. file_put_contents("ss.txt",$f_tt);  
  122. echo "<script>location.href='wenwen.php?jl=".$jl."&sp=".$sp."&pg=".$pg."&rs=".$rs." ';</script>";  
  123. exit();  
  124. }  
  125. ?>  
  126. <link href="style.css教程" rel="stylesheet" type="text/css" />  
  127. <table width="700" border="0" align="center" cellspacing="1" bgcolor="#cccccc">  
  128. <tr>  
  129. <td height="50" align="center" bgcolor="#00cc00"><h1><a href="http://www.111cn.net">薦禮啦</a>知道問問采集插件</h1></td>  
  130. </tr>  
  131. </table>  
  132. <table width="700" border="0" align="center" cellspacing="1" bgcolor="#cccccc" style="margin-top:6px; margin-bottom:6px;">  
  133. <tr>  
  134. <td height="30" align="center" bgcolor="#ffffff"><a href="cj_config.php">采集設置</a> <a href="uninstall.php" onclick="return confirm('您確定要卸載采集插件嗎');">卸載采集</a> <a href="cj_view.php">查看采集記錄</a> <a href="cj_help.php">采集幫助</a> <a href="baidu.php" target="_blank">知道采集</a> <a href="wenwen.php" target="_blank">問問采集</a></td>  
  135. </tr>  
  136. </table>  
  137. <form action="wenwen.php" method="post">  
  138. <table width="628" height="49" border="0" align="center">  
  139. <tr> //開源代碼Vevb.com 
  140. <td width="413" align="right"><input name="ask" type="text" id="ask" size="50"></td>  
  141. <td width="205"><input type="submit" name="button" id="button" value="問問采集" style=" padding-left:15px; padding-right:15px; height:25px; line-height:25px;"></td>  
  142. </tr>  
  143. </table>  
  144. </form> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 微山县| 郑州市| 河西区| 全南县| 鹿邑县| 嘉定区| 象州县| 临江市| 郴州市| 措勤县| 深州市| 大石桥市| 南皮县| 西平县| 大安市| 黄大仙区| 临夏市| 桐梓县| 邵武市| 鸡西市| 策勒县| 安福县| 榆中县| 广德县| 新闻| 汤阴县| 额敏县| 邢台县| 抚顺市| 浦江县| 五大连池市| 迁西县| 临夏市| 颍上县| 丽水市| 清远市| 洛川县| 轮台县| 乌拉特中旗| 普格县| 临桂县|