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

首頁 > 開發(fā) > PHP > 正文

php獲取百度收錄、百度熱詞及百度快照的方法

2024-05-04 23:33:46
字體:
供稿:網(wǎng)友

這篇文章主要介紹了php獲取百度收錄、百度熱詞及百度快照的方法,實(shí)例分析了php抓取百度頁面及對(duì)應(yīng)字符串分析的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了php獲取百度收錄、百度熱詞及百度快照的方法。分享給大家供大家參考。具體如下:

獲取百度收錄:
 

  1. <?php 
  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("找到相關(guān)網(wǎng)頁(.*)篇,"$site,$count); 
  10. $count=str_replace("找到相關(guān)網(wǎng)頁","",$count); 
  11. $count=str_replace("篇,","",$count); 
  12. $count=str_replace("約","",$count); 
  13. $count=str_replace(",","",$count); 
  14. return $count[0]; 
  15. echo baidu(m.survivalescaperooms.com); 
  16. //獲取武林網(wǎng)在百度中的收錄數(shù)量 
  17. ?> 

獲取百度的熱詞
 

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

這是在網(wǎng)上找的 稍微修改了下 將下面代碼寫入php文件

百度收錄和百度快照時(shí)間

 

 
  1. <?php 
  2. $domain = "http://m.survivalescaperooms.com/ *欲查詢的域名*/ 
  3. $site_url = 'http://www.baidu.com/s?wd=site%3A'
  4. $all = $site_url.$domain/*域名所有收錄的網(wǎng)址*/ 
  5. $today = $all.'&lm=1′; /*域名今日收錄的網(wǎng)址*/ 
  6. $utf_pattern = "/找到相關(guān)結(jié)果數(shù)(.*)個(gè)/"
  7. $kz_pattern = "/<span class="g">(.*)</span>/"/*用以匹配快照日期的字符串*/ 
  8. $times = "/d{4}-d{1,2}-d{1,2}/"/*匹配快照日期的正則表達(dá)式,如:2011-8-4*/ 
  9. $s0 = @file_get_contents($all); /*將site:m.survivalescaperooms.com的網(wǎng)頁置入$s0字符串中*/ 
  10. $s1 = @file_get_contents($today); 
  11. preg_match($utf_pattern,$s0,$all_num); /*匹配"找到相關(guān)結(jié)果數(shù)*個(gè)"*/ 
  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時(shí)');?> </td><td> 
  33. <?php echo $all_num[1]; ?></td><td> 
  34. <?php echo $today_num[1]; ?></td><td> 
  35. <?php echo $screenshot[0]; ?></td> 
  36. </tr> 
  37. </table> 
  38. <p>百度收錄:<a href="<?php echo $all; ?>" target="_blank"
  39. <?php echo $all_num[1]; ?></a></p> 
  40. <p>百度今日收錄:<a href="<?php echo $today; ?>" target="_blank"
  41. <?php echo $today_num[1]; ?></a></p> 
  42. <p>百度快照日期:<a href="<?php echo $all; ?>"
  43. <?php echo $screenshot[0]; ?></a></p> 
  44. </body> 
  45. </html> 

希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 金华市| 嘉荫县| 永靖县| 曲水县| 连州市| 昂仁县| 盘山县| 鹿邑县| 车致| 巴林左旗| 新田县| 华蓥市| 盐边县| 咸丰县| 邵武市| 寿阳县| 德州市| 望城县| 军事| 余庆县| 乐东| 湘乡市| 西畴县| 肇源县| 峨眉山市| 金平| 互助| 陈巴尔虎旗| 武山县| 收藏| 新竹市| 水富县| 革吉县| 玉环县| 木兰县| 清苑县| 资源县| 河津市| 曲周县| 北安市| 基隆市|