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

首頁 > 開發 > PHP > 正文

php抓取百度快照、百度收錄、百度熱詞程序代碼

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

如果大家稍加仔細看一下就能發現一個問題,我們下面幾個抓取百度收錄或快照或熱詞的程序中都有一個函數file_get_contents(),他是php采集網頁常用的哦。

  1. <? 
  2. /* 
  3. 抓取百度收錄代碼 
  4. */ 
  5. function baidu($s){ 
  6.   $baidu="http://www.baidu.com/s?wd=site%3A".$s
  7.   $site=file_get_contents($baidu); 
  8.   //$site=iconv("gb2312", "UTF-8", $site); 
  9.   ereg("找到相關網頁(.*)篇,"$site,$count); 
  10.   $count=str_replace("找到相關網頁","",$count); 
  11.   $count=str_replace("篇,","",$count); 
  12.   $count=str_replace("約","",$count); 
  13.   $count=str_replace(",","",$count); 
  14.   return $count[0]; 
  15. echo baidu(www.hzhuti.com); //獲取好主題在百度中的收錄數量 
  16. ?> 

獲取百度的熱詞

  1. <?php  
  2. /**  
  3. * * @user 小杰  
  4. * @return array 返回百度的熱詞數據(數組返回)  
  5. */  
  6. function getBaiduHotKeyWord()  
  7. {  
  8. $templateRss = file_get_contents('http://top.baidu.com/rss_xml.php?p=top10');  
  9. If (preg_match('/<table>(.*)</table>/is'$templateRss$_description)) {  
  10. $templateRss = $_description [0];  
  11. $templateRss = str_replace("&""&"$templateRss);  
  12. }  
  13. $templateRss = "<?xml version="1.0" encoding="GBK"?>" . $templateRss;  
  14. $xml = simplexml_load_String($templateRss);  
  15. foreach ($xml->tbody->tr as $temp) {  
  16. if (!emptyempty ($temp->td->a)) {  
  17. $keyArray [] = trim(($temp->td->a));  
  18. }  
  19. }  
  20. return $keyArray;  
  21. }  
  22. print_r(getBaiduHotKeyWord()); 

 

這是在網上找的,稍微修改了下,將下面代碼寫入php文件,百度收錄和百度快照時間
  1. <?php 
  2.     $domain = “http://m.survivalescaperooms.com/nokia/5230/ *欲查詢的域名*/ 
  3.     $site_url = ‘http://m.survivalescaperooms.com/s?wd=site%3A’; 
  4.     $all = $site_url.$domain/*域名所有收錄的網址*/ 
  5.     $today = $all.’&lm=1′;    /*域名今日收錄的網址*/ 
  6.     $utf_pattern = “/找到相關結果數(.*)個/”; 
  7.     $kz_pattern = “/<span class=”g”>(.*)</span>/”; /*用以匹配快照日期的字符串*/ 
  8.     $times = “/d{4}-d{1,2}-d{1,2}/”; /*匹配快照日期的正則表達式,如:2011-8-4*/ 
  9.     $s0 = @file_get_contents($all);    /*將site:www.Vevb.net的網頁置入$s0字符串中*/ 
  10.     $s1 = @file_get_contents($today); 
  11.     preg_match($utf_pattern,$s0,$all_num); /*匹配”找到相關結果數*個”*/ 
  12.     preg_match($utf_pattern,$s1,$today_num); 
  13.     preg_match($kz_pattern,$s0,$temp); 
  14.     preg_match($times,$temp[0],$screenshot); 
  15.     if($all_num[1] == “”) 
  16.         $all_num[1] = 0; 
  17.     if($today_num[1] == “”) 
  18.         $today_num[1] = 0; 
  19.     if($screenshot[0] == “”) 
  20.         $screenshot[0] = “暫無快照”; 
  21. ?> 
  22. <html> 
  23.     <head> 
  24.     <title>Test</title> 
  25.     </head> 
  26. <body> 
  27.   <table> 
  28.     <tr> 
  29.       <td>日期</td><td>百度收錄</td><td>百度今日收錄</td><td>百度快照日期</td> 
  30.     </tr> 
  31.     <tr> 
  32.       <td><?php echo date(‘m月d日G時’);?> </td><td><?php echo $all_num[1]; ?></td><td><?php echo $today_num[1]; ?></td><td><?php echo $screenshot[0]; ?></td> 
  33.     </tr> 
  34.   </table> 
  35.     <p>百度收錄:<a href=”<?php echo $all; ?>” target=”_blank”><?php echo $all_num[1]; ?></a></p> 
  36.     <p>百度今日收錄:<a href=”<?php echo $today; ?>” target=”_blank”><?php echo $today_num[1]; ?></a></p> 
  37.     <p>百度快照日期:<a href=”<?php echo $all; ?>”><?php echo $screenshot[0]; ?></a></p> 
  38. </body> 
  39. </html> 

上面的方法未經過嚴格考慮,如果服務器不支持file_get_contents函數我們就無法操作了,所以還可以利用curl操作,這個更方便可以模仿用戶哦。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 行唐县| 淅川县| 伊通| 江津市| 独山县| 江源县| 巴林右旗| 白银市| 藁城市| 江都市| 什邡市| 大宁县| 海安县| 临武县| 济源市| 沿河| 平凉市| 松阳县| 厦门市| 林甸县| 库车县| 堆龙德庆县| 大悟县| 龙川县| 同仁县| 梁山县| 宽城| 莱阳市| 沐川县| 刚察县| 吉隆县| 曲麻莱县| 汾阳市| 兰州市| 黔江区| 安丘市| 陇西县| 阿勒泰市| 乌鲁木齐县| 桂东县| 遂平县|