Home > Backend Development > PHP Tutorial > PHP获取百度关键词排名

PHP获取百度关键词排名

PHP中文网
Release: 2016-05-17 09:40:36
Original
1181 people have browsed it

PHP获取百度关键词排名

PHP代码

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

@$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(&#39;/<div class=\"f13\">(.*?)<\/div>/si&#39;, $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


Related labels:
php
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template