Use Yahoo! Search API development self-developed search engine-JavaScript version

Source: Internet
Author: User

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/

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.