Home > php教程 > PHP源码 > body text

PHP gets Baidu keyword ranking

不言
Release: 2018-05-19 11:39:20
Original
4258 people have browsed it

Jump to [1] [2]                                                                                                                               [Full screen preview]

@$k=$_GET['k'] ? $_GET['k'] : '不念博客';
@$u=$_GET['u'] ? $_GET['u'] : 'www.bunian.cn';
$rn='50';
$url = "https://www.baidu.com/s?ie=utf-8&wd=".$k."&rn=".$rn;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.1 Safari/537.11');
$res = curl_exec($ch);
$rescode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
preg_match_all('/(.*?)/si', $res, $p);
for ($ii = 0; $ii < COUNT($p[1]); $ii++){
$pos=strpos($p[1][$ii],$u);
if(is_integer($pos)){
$rn= $ii+1;
break;
}
}
echo $rn;
Copy after login

2. [Code][PHP]Code Jump to [1] [2]                                                                                                                               [Full screen preview]

欢迎大家来我的博客做客
Copy after login

3. [Code][PHP]Code Jump to [1] [2]                                                                                                                               [Full screen preview]                                                                                        

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!