脚本宝典收集整理的这篇文章主要介绍了php – 如何从Google查询中获取结果数量,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我在Google自定义搜索API上找不到任何关于如何执行此操作的参考资料,所以我已经构建了一个小型的刮刀,但我觉得这不是最好的方法.这是我的代码:
<?PHP $url = "http://www.google.COM/seArch?q=".$keyword; $text = file_get_contents($url); //get string between 2 strings function function get_string_between($string,$start,$end){ $string = " ".$string; $ini = strpos($string,$start); if ($ini == 0) return ""; $ini += strlen($start); $len = strpos($string,$end,$ini) - $ini; return substr($string,$ini,$len); } //fetch the string between "About" and "results" $res = get_string_between($text,"About","results"); //keep only numeric characters $res = PReg_replace('/[^0-9]+/','',$res); ?>
你能建议一个更好的方法吗? (最好使用Google Api)
$params = array('q' => 'shark wITh lasers that shoot monkeys with balloons on skyscraPErs please give me less results asdafasdDFg'); $content = file_get_contents('http://www.google.com/search?' . http_build_query($params)); preg_match('/About (.*) results/i',$content,$matches); echo !empty($matches[1]) ? $matches[1] : 0; // output: 14,300
我在他们的API中找不到任何东西.请注意,这是针对Google TOS的. Bing的API将为您提供结果计数.
以上是脚本宝典为你收集整理的php – 如何从Google查询中获取结果数量全部内容,希望文章能够帮你解决php – 如何从Google查询中获取结果数量所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。