Yang Zhiyuan, co-founder of Yahoo!, will announce that the company's search network will enter Web Services on July 15, March 1. Yahoo! has established the Yahoo Search Developer Network on www.developer.yahoo.com. The company plans to launch this plan at the search engine Strategies conference held in New York. This network will allow developers to create new applications for Yahoo Search, including images, videos, news, and regional searches. Members who want to use this service must first go to the http://api.search.yahoo.com/webservices/register_application to apply for a self-idnumber, Note: Each idnumber can only search 5000 times a day.
Next, let's take a look at how to use JavaScript scripts to call Yahoo! Search by using the search API. All scripts are as follows:
/*
* Yahoo_search_api.js
* Part of the Yahoo! Search sidebar for Firefox
* Powered by Yahoo! Search Web Services (http://api.search.yahoo.com)
* Written by Marc Abramowitz (http://marc.abramowitz.info)
* Copyright (c) 2005 Yahoo! Inc.
* Www.knowsky.com
*/
Function yahoo_search (){}
Yahoo_search.baseurl = function (){
Return "http://api.search.yahoo.com/WebSearchService/V1 ";
}
Yahoo_search.appid = function (){
Return "yahoosearchsidebar ";
}
Yahoo_search.baseargs = function (){
Return "appid =" + this. appid ();
}
Yahoo_search.results = function (ARGs ){
VaR xmlurl = This. baseurl () + "Websearch? "
+ This. baseargs ()
+ "& Query =" + ARGs ["Doc"]
+ "& Zip ="
+ "& START =" + ARGs ["first"]
+ "& Results =" + ARGs ["count"];
VaR XMLHTTP = new XMLHttpRequest ();
XMLHTTP. Open ("get", xmlurl, false );
XMLHTTP. Send (null );
Return this. readxml (XMLHTTP. responsexml );
}
Yahoo_search.readxml = function (xmldoc ){
Try {
VaR retval = new array ();
VaR resultset = xmldoc. getelementsbytagname ("resultset") [0];
VaR totalresultsavailable = parseint (resultset. getattribute ("totalresultsavailable "));
VaR totalresultsreturned = parseint (resultset. getattribute ("totalresultsreturned "));
VaR firstresultposition = parseint (resultset. getattribute ("firstresultposition "));
VaR start = firstresultposition;
VaR end = firstresultposition + totalresultsreturned-1;
VaR Results = xmldoc. getelementsbytagname ("result ");
For (VAR I = 0; I <results. length; I ++ ){
VaR result = Results [I];
VaR Title = result. getelementsbytagname ('title') [0]. firstchild. nodevalue;
VaR summary = '';
If (result. getelementsbytagname ('summary ') [0]. firstchild ){
Summary = result. getelementsbytagname ('summary ') [0]. firstchild. nodevalue;
}
VaR clickurl = result. getelementsbytagname ('clickurl') [0]. firstchild. nodevalue;
VaR url = result. getelementsbytagname ('url') [0]. firstchild. nodevalue;
Retval [I] = {I: Start + I, Title: title, summary: Summary, clickurl: clickurl, URL: URL };
}
Return retval;
} Catch (exception ){
Alert ('exception occurred while reading XML (I = '+ I +'; Start = '+ start +'; end = '+ end +'): '+ exception );
}
}
Interested friends can also take a look at the [dynamic website Production Guide] produced by ASP version: http://www.knowsky.com/yahoo/