最模板 - 外贸网站建设,外贸网站模板

最模板

当前位置: 首页 > 建站教程 > php教程 >

php 问问采集代码

时间:2014-09-09 10:57来源:未知 作者:最模板zuimoban 点击:
提供一款免费的php 问问采集代码,如果你正想采集问问,但是又不知道怎么写采集程序,这里为你提供一款经典的问问采集程序,代码如下: ?php session_start(); header( content-type:text/html;charset=u

提供一款免费的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> //开源代码vcphp.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> 
  145.  
(责任编辑:最模板)
------分隔线----------------------------
栏目列表
推荐内容