利用Yahoo! Search API开发自已的搜索引擎-javascript版
下面我们看一下,如何用javascript脚本调用Yahoo! Search API实现搜索的效果,全部脚本如下:
dedecms.com
/*
* 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() {} 内容来自dedecms
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();
} dedecms.com
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);
} 内容来自dedecms
Yahoo_Search.readXML = function (xmlDoc) {
try {
var retVal = new Array();
var resultSet = xmlDoc.getElementsByTagName("ResultSet")[0];
var totalResultsAvailable = parseInt(resultSet.getAttribute("totalResultsAvailable"));
文章评论
共有位Admini5网友发表了评论 查看完整内容