php 获取排名,PHP 获取文章在百度排名的实例代码

/**

* $key 百度搜索关键词

* $url 要查找的文章的URL(可把标题传进来)

* $max 从百度搜索结果的前多少条查找

*

* return $rank

*

* @site www.jbxue.com

*/

function get_con($key='', $url='', $max=100, $pn=0){

if(!$pn) $key = iconv("UTF-8","GB2312",$key);

$str  = "http://www.baidu.com/s?wd=".urlencode($key).'&pn='.$pn;

$str  = file_get_contents($str);

preg_match_all("/

foreach ($match[0] as $key => $val){

if(strstr($val, $url)) {

$rank = $match[1][$key];

break;

}

}

if($rank) {

return $rank;exit;

}else{

$pn += 10;

if($pn > $max) {

return 0;exit;

}

$rank = get_con($key, $url, $max, $pn);

}

return $rank;

}

$res = get_con('中国足球', 'http://zhidao.baidu.com/question/205692751.html?si=10&wtp=wk');

print_r($res);

//相关记录条数

function baidu_total($key='') {

$key  = iconv("UTF-8","GB2312",$key);

$str  = "http://www.baidu.com/s?wd=".urlencode($key);

$ct   = file_get_contents($str);

$preg = iconv("UTF-8", "GB2312", "/找到相关网页约[\s\S]*?篇/");

preg_match($preg, $ct, $match);

$str = iconv("GB2312","UTF-8",$match[0]);

return $str;

}

//调用示例 取得百度排名

$res = baidu_total('"脚本学堂"');

print_r($res);

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值