源码
资讯
  当前位置:源码网网络学院建站指南网站运营 → 利用Yahoo! Search API开发自已的搜索引擎-php版
特别推荐
热点TOP10
本周下载排行
本月下载排行
利用Yahoo! Search API开发自已的搜索引擎-php版
日期:2006年3月26日 作者: 人气: 查看: [大字体 中字体 小字体]
美国东部时间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'); ?>
Search Term:
Zip Code: (for local search)
\n"; echo " Node : " . $errorline['nodename'] . "
\n"; echo " Line : " . $errorline['line'] . "
\n"; echo " Column : " . $errorline['col'] . "
\n"; } done(); } // Now traverse the DOM with this function // It is basically a generic parser that turns limited XML into a PHP array // with only a couple of hardcoded tags which are common across all the // result xml from the web services function xml_to_result($dom) { $root = $dom->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<$res['totalResultsReturned']; $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 < $res['totalResultsAvailable']) echo 'Next Page->'; done(); ?>

(出处:动态网站制作指南)

百度搜索 Google搜索 雅虎搜索 我要投稿
相关文章: 相关软件: