Yos*_*sef 2 php gdata-api gdata zend-gdata
如何获取谷歌搜索结果网址?
(我使用Zend_Gdata_Gbase获取搜索谷歌搜索结果而不是DomDocument/htmlsimpleparser,因为它看起来Zend_Gdata_Gbase专门用于解析谷歌搜索结果.如果我的选择错误,请写.)
我的功能是获取'yahoo'或其他查询搜索字符串的google搜索结果:( 该函数获取的搜索结果应该包含'yahoo'字样,但是当我使用prin_t($ feed)时,我看不到网址每个结果)
<?php
function queryGoogleSearch($queryString='yahoo'){
$service = new Zend_Gdata_Gbase();
$query = $service->newSnippetQuery();
$query->setBq('['.$queryString.']');
$query->setOrderBy('modification_time');
$query->setSortOrder('descending');
$query->setMaxResults('4');
$feed = $service->getGbaseSnippetFeed($query);
return $feed;
}
print_r(queryGoogleSearch());
?>
Run Code Online (Sandbox Code Playgroud)
我得到4个第一个网址结果(当我在谷歌手动搜索时):
www.yahoo.com,mail.yahoo.com,search.yahoo.com,maps.yahoo.com
但是当我打印$ feed变量时,我找不到它们.
请问我应该更改或添加inqueryGoogleSearch()函数?(或其他更好的代码)
谢谢
您是否正在尝试搜索google.com.看起来该类适用于Google Base,而不是google.com搜索引擎.http://base.google.com/support/bin/answer.py?hl=en&answer=59260
你可能想要这个:http://code.google.com/apis/customsearch/v1/overview.html 他们最近刚改变了这个.旧的Google搜索API现已于11月1日弃用.自定义搜索是新的API.
没有Zend,它非常简单易用.
http://code.google.com/apis/customsearch/v1/using_rest.html#WorkingResults
PHP中有一个JSON解码器. http://php.net/manual/en/function.json-decode.php
希望有所帮助!
| 归档时间: |
|
| 查看次数: |
5074 次 |
| 最近记录: |