javascript|yahoo| search engine U.S. Eastern Time March 1, Yahoo co-founder of one of Jerry Yang will announce the company's search network will enter the Web services. Yahoo Company in
www.developer.yahoo.comThe website has established Yahoo Search Developer Network, the company plans to launch the program at the Search engine Strategy Conference in New York (Search Engine Strategies Conference). The network will allow developers to build new applications on top of Yahoo's search, including images, videos, news, and regional searches. Members who want to use this service must go first
http://api.search.yahoo.com/webservices/register_applicationRequest a Self ID number, note: Each ID number can only be searched 5,000 times a day.
Let's take a look at how to invoke Yahoo! with JavaScript script The search API implements the results of the searches, all scripts are as follows:
/*
* Yahoo_search_api.js
* 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), 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["a"
+ "&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 ASP version produced by the [Dynamic Web site Production Guide]:http://www.knowsky.com/yahoo/