PHP:使用preg_match(非Google API)提取Google中索引页面的数量

PHP:使用preg_match(非Google API)提取Google中索引页面的数量,php,preg-match,serp,Php,Preg Match,Serp,我正在使用cURL获取Google中某个搜索结果的数量 我使用preg_match提取如下数据: preg_match('/About (.*?) results/sim',$google_url_contents, $regs) preg_match('/Results .*? of about (.*?) from/sim', $google_url_contents, $regs) <div id="resultStats">6 results<nobr> (

我正在使用cURL获取Google中某个搜索结果的数量

我使用preg_match提取如下数据:

preg_match('/About (.*?) results/sim',$google_url_contents, $regs)
preg_match('/Results .*? of about (.*?) from/sim', $google_url_contents, $regs)
<div id="resultStats">6 results<nobr>  (0.11 seconds)&nbsp;</nobr></div>
就像这样:

preg_match('/About (.*?) results/sim',$google_url_contents, $regs)
preg_match('/Results .*? of about (.*?) from/sim', $google_url_contents, $regs)
<div id="resultStats">6 results<nobr>  (0.11 seconds)&nbsp;</nobr></div>
然而,对于少于10个结果,我在数字之前没有文本字符串,所以我不知道如何解析它

Google提供的HTML输出如下所示:

preg_match('/About (.*?) results/sim',$google_url_contents, $regs)
preg_match('/Results .*? of about (.*?) from/sim', $google_url_contents, $regs)
<div id="resultStats">6 results<nobr>  (0.11 seconds)&nbsp;</nobr></div>
6个结果(0.11秒)
在本例中,如何将6提取为整数


注意:我暂时不想使用谷歌搜索API

你可以使用
preg\u match('/resultStats\D*([\D,]+)/,$line,$matches)


\D
表示非数字字符<代码>\D*为0个或更多非数字字符
[\d,]
是一个数字或逗号的字符类,
[\d,]+
表示一个或多个字符类。

您能否给出一个搜索结果少于10个的示例?另外,使用正则表达式解析HTML在这里就像是一种耻辱\d代表任何数字\d+表示一个或多个数字。[0-9]+是介于0和9之间的任意数字中的一个或多个。换句话说,您可以使用
/\d+results/
我知道RegEx不受欢迎。。。下面是一个搜索结果少于10个的示例:
http://www.google.com/#q=site:www.yogamesana.com