(PHP) 如何解析Google搜索结果中的URL?
如何获取google搜索结果的url?
(我使用 Zend_Gdata_Gbase 来获取搜索谷歌结果,而不是 DomDocument/htmlsimpleparser ,因为在我看来,Zend_Gdata_Gbase 专门用于解析谷歌结果。 如果我的选择错误,请写下来。)
我获取“yahoo”或其他查询搜索字符串的谷歌搜索结果的函数: (该函数获取的 feed 应该包含单词“yahoo”的搜索结果,但是当我使用 prin_t($feed) 时,我看不到每个结果的 url)
<?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());
?>
我得到 4 个第一个 url 结果(当我在 google 中手动搜索时) :
www.yahoo.com、mail.yahoo.com、search.yahoo.com、maps.yahoo.com
但是当我打印 $feed 变量时我找不到它们。
请问我应该更改或添加 inqueryGoogleSearch() 函数吗? (或其他更好的代码)
谢谢
How get google search results url?
(I use Zend_Gdata_Gbase for get search google results and not DomDocument/htmlsimpleparser because its looks to me that Zend_Gdata_Gbase done specially for parsing google results.
if I wrong in my selection, please write.)
My function to get google search results for 'yahoo' or other query search string:
(the function get a feed that should have search result for word 'yahoo', but when i use prin_t($feed) I don't see url for each result)
<?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());
?>
I get 4 first url results (when I search manually in google):
www.yahoo.com, mail.yahoo.com, search.yahoo.com, maps.yahoo.com
But I can't find them when I print $feed variable.
Please what should i change or add inqueryGoogleSearch() function? (Or other better code)
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否正在尝试搜索 google.com?看起来该类适用于 Google Base,而不是 google.com 搜索引擎。 http://base.google.com/support/bin/answer.py? hl=zh-CN&answer=59260
您可能需要这个:http://code.google。 com/apis/customsearch/v1/overview.html
他们最近刚刚改变了这一点。自 11 月 1 日起,旧的 Google 搜索 API 现已弃用。自定义搜索是新的 API。
无需 Zend,使用起来非常简单。
http://code.google.com/apis/customsearch/v1/using_rest.html#WorkingResults< /a>
PHP 中有一个 JSON 解码器。
希望
这有帮助!
Are you trying to search google.com. Looks like that class is for Google Base, not google.com search engine. http://base.google.com/support/bin/answer.py?hl=en&answer=59260
You probably want this: http://code.google.com/apis/customsearch/v1/overview.html
They recently just changed this. The old google search API has now deprecated as of Nov 1st. Custom search is the new API.
Its pretty simple to use without Zend.
http://code.google.com/apis/customsearch/v1/using_rest.html#WorkingResults
There is a JSON decoder in PHP.
http://php.net/manual/en/function.json-decode.php
Hope that helps!