Using Yahoo! Search API develops its own-javascript version

Source: Internet
Author: User
Tags return version web services yahoo co
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/



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.