yahoo
美国东部时间3月1日,雅虎公司联合创始人之一的杨致远将宣布公司的搜索网络将进入web服务。雅虎公司在www.developer.yahoo.com网站建立了yahoo search developer network,公司计划在此纽约举行的搜索引擎战略大会(search engine strategies conference)上推出这一计划。该网络将允许开发者在雅虎搜索之上建立新的应用程序,其中包括图像、视频、新闻以及地区搜索等内容。想要使用这项服务的会员必须先去http://api.search.yahoo.com/webservices/register_application 申请一个自已的id号,注:每个id号每天只能搜索5000次。
下面我们看一下,如何用php脚本调用yahoo! search api实现搜索的效果,全部脚本如下:
'http://api.search.yahoo.com/imagesearchservice/v1/imagesearch',
'local'=>'http://api.local.yahoo.com/localsearchservice/v1/localsearch',
'news'=>'http://api.search.yahoo.com/newssearchservice/v1/newssearch',
'video'=>'http://api.search.yahoo.com/videosearchservice/v1/videosearch',
'web'=>'http://api.search.yahoo.com/websearchservice/v1/websearch');
?>
php yahoo web service example code
search term:
zip code: (for local search)
$val) {
if(!empty($_request['type']) && $name == $_request['type'])
echo $name\n;
else echo $name\n;
} ?>
document_element();
$res['totalresultsavailable'] = $root->get_attribute('totalresultsavailable');
$res['totalresultsreturned'] = $root->get_attribute('totalresultsreturned');
$res['firstresultposition'] = $root->get_attribute('firstresultposition');
$node = $root->first_child();
$i = 0;
while($node) {
switch($node->tagname) {
case 'result':
$subnode = $node->first_child();
while($subnode) {
$subnodes = $subnode->child_nodes();
if(!empty($subnodes)) foreach($subnodes as $k=>$n) {
if(empty($n->tagname)) $res[$i][$subnode->tagname] = trim($n->get_content());
else $res[$i][$subnode->tagname][$n->tagname]=trim($n->get_content());
}
$subnode = $subnode->next_sibling();
}
break;
default:
$res[$node->tagname] = trim($node->get_content());
$i--;
break;
}
$i ;
$node = $node->next_sibling();
}
return $res;
}
$res = xml_to_result($dom);
// ok, now that we have the results in an easy to use format,
// display them. it's quite ugly because i am using a single
// display loop to display every type and i don't really understand html
$first = $res['firstresultposition'];
$last = $first $res['totalresultsreturned']-1;
echo
matched ${res[totalresultsavailable]}, showing $first to $last
\n;
if(!empty($res['resultsetmapurl'])) {
echo result set map: ${res[resultsetmapurl]}
\n;
}
for($i=0; $i foreach($res[$i] as $key=>$value) {
switch($key) {
case 'thumbnail':
echo \n;
break;
case 'cache':
echo cache: ${value[url]} [${value[size]}]
\n;
break;
case 'publishdate':
echo $key: .strftime('%x %x',$value);
break;
default:
if(stristr($key,'url')) echo $value
\n;
else echo $key: $value
;
break;
}
}
echo \n;
}// create previous/next page links
if($start > 1)
echo '<-previous page ';
if($last
有兴趣的朋友还可以看一下由[动态网站制作指南]所制作的asp版本:http://www.knowsky.com/yahoo/