本帖最后由 无名小银 于 2019-6-28 11:29 编辑
百度关键词排名批量查询,可以批量查询一个网站的所有关键词,支持查询100名以内
演示网站:
[Asm] 纯文本查看 复制代码 https://www.bunian.cn/gongjv/bdrk/
网站截图
核心源代码
[PHP] 纯文本查看 复制代码 function curl($key,$pn=0)
{
$pn= "";
if($pn){
$pn= "&pn=".(($pn*50)-50);
}
$url = "https://www.baidu.com/s?ie=utf8&wd=". urlencode($key) ."&rn=50".$pn;
set_time_limit(0);
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.81 Safari/537.36 SE 2.X MetaSr 1.0");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS,20);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 40);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
curl_close($ch);
preg_match('/<div id=\"content_left\">(.*?)<div style=\"clear:both;height:0;\"><\/div>/is', $result, $matches);
return $matches[1];
}
function wordkey($word,$site)
{
$bd=curl($word).curl($word,'2');
preg_match_all('/<(.*?) id=\"([0-9]{1,4})\"(.*?)>(.*?)<div class="f13">(.*?)<\/a>/is', $bd , $matches);
$lid=$matches[2];
$id=array();
foreach($matches[5] as $key => $value){
if(strpos($value,$site) !== false){
$id[]=$lid[$key];
}
}
return json_encode([
'word'=>$word,
'site'=>$site,
'rank'=>$id,
]);
}
土豪通道:
百度排名查询.zip
(933.64 KB, 下载次数: 430)
Github通道
https://github.com/bunian/baidu-key-rk
|