abstract:這篇文章主要介紹了PHP簡單獲取網(wǎng)站百度搜索和搜狗搜索收錄量的方法,涉及php網(wǎng)頁文件的讀取及正則替換的相關(guān)操作技巧,需要的朋友可以參考下.本文實例講述了PHP簡單獲取網(wǎng)站百度搜索和搜狗搜索收錄量的方法。分享給大家供大家參考,具體如下:獲取網(wǎng)站百度搜索和搜狗搜索的收錄量代碼,可以用于獲取網(wǎng)站域名在搜索引擎的收錄數(shù)量,一直想找這個API但沒找到,就在網(wǎng)上找了個例子,學(xué)習(xí)修改了下,可以正常獲取百度搜索
這篇文章主要介紹了PHP簡單獲取網(wǎng)站百度搜索和搜狗搜索收錄量的方法,涉及php網(wǎng)頁文件的讀取及正則替換的相關(guān)操作技巧,需要的朋友可以參考下.
本文實例講述了PHP簡單獲取網(wǎng)站百度搜索和搜狗搜索收錄量的方法。分享給大家供大家參考,具體如下:
獲取網(wǎng)站百度搜索和搜狗搜索的收錄量代碼,可以用于獲取網(wǎng)站域名在搜索引擎的收錄數(shù)量,一直想找這個API但沒找到,就在網(wǎng)上找了個例子,學(xué)習(xí)修改了下,可以正常獲取百度搜索和搜狗搜索的收錄量了;原理是獲取搜索引擎site:domain的結(jié)果數(shù)量,然后再抓取這個數(shù)量顯示出來。
function baidu($url){ $baidu="http://www.baidu.com/s?wd=site:".$url; $site=file_get_contents($baidu); ereg("該網(wǎng)站共有(.*)個網(wǎng)頁被百度收錄", $site,$count); $count=str_replace("該網(wǎng)站共有","",$count); $count=str_replace("個網(wǎng)頁被百度收錄","",$count); $count=str_replace(",","",$count); $count=str_replace(" ","",$count); return strip_tags($count[0]); } function sogou($url){ $sogou="http://www.sogou.com/web?query=site:".$url; $site=file_get_contents($sogou); ereg("找到約 (.*) 條結(jié)果", $site,$count); $count=str_replace("找到約","",$count); $count=str_replace("條結(jié)果","",$count); $count=str_replace(",","",$count); $count=str_replace(" ","",$count); return strip_tags($count[0]); } ?> www.jb51.net 百度收錄<?php echo baidu('www.jb51.net');?>條<br> www.jb51.net 搜狗收錄<?php echo sogou('www.jb51.net');?>條
更多關(guān)于PHP簡單獲取網(wǎng)站百度搜索和搜狗搜索收錄量的方法請關(guān)注PHP中文網(wǎng)(m.miracleart.cn)其它文章!