Home  >  Article  >  Backend Development  >  获取关键字百度排名位数的方法,主要应该是正则表达式,该如何解决

获取关键字百度排名位数的方法,主要应该是正则表达式,该如何解决

WBOY
WBOYOriginal
2016-06-13 13:40:32656browse

获取关键字百度排名位数的方法,主要应该是正则表达式
例如从百度搜索csdn,
获取的结果部份如下:

HTML code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->


其中

中的 id="1" 的 1则是以csdn为关键字时,www.csdn.net的百度自然排名。在 "'})" href="http://www.csdn.net/"target="_blank">"这串字符前数第15个字符,也是他的排名数字 1
我现在只能file_get_contents获取到整个的搜索结果,如何“提炼”出这个 id="1" 的 1呢? 请各位指教,谢谢!

我的思路是,从"'})" href="http://www.csdn.net 这段代码向前搜索第15个字条,获取他,也可以。

请各位指教,谢谢!

------解决方案--------------------
2点了,居然没人回答,看样子都在昏迷了。

$Str='
}';
$Pat='/id="([0-9])+"/';
preg_match($Pat, $Str,$Marray);
echo $Marray[1];
Statement:
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