Using Yahoo! Search API develops its own-javascript version

Source: Internet
Author: User
Tags return version web services
Yahoo| Search Engine

U.S. Eastern Time March 1, Yahoo co-founder of one of the founders of Jerry Yang will announce the company's search network will enter the Web services. Yahoo Search Developer Network was set up in the Www.developer.yahoo.com website, and the company plans to hold a search engine strategy conference in New York (Search Engine Strategies Conference) on the launch of the plan. 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 first go to http://api.search.yahoo.com/webservices/register_application to apply for a self ID number, note: Each ID number can only be searched 5,000 times per 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

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

Starter Package

SSD Cloud server and data transfer for only $2.50 a month

Get Started >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.