使用google的API进行搜索


 <div>

        <script src="http://www.google.com/uds/api?file=uds.js&v=1.0&key=ABQIAAAAFMNM-64tTfERUyU8p2vwDBQmgMplEgC625_ygl3JiS1gYnM1cBTS2XQhrkScec6Gf9z-xJdH47i6lQ"
            type="text/javascript"></script>

        <script type="text/javascript">
function OnSearchLoad(searchStr)
{
  // Create a search control
    var searchControl = new GSearchControl();
    var options = new GsearcherOptions();
    options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
    var WebSearch = new GnewsSearch();
    searchControl.addSearcher(WebSearch,options);
    WebSearch.setSearchCompleteCallback(this,GetResult,[WebSearch]);
    //searchControl.addSearcher(new GblogSearch(),options);      这是blog搜索
    //searchControl.addSearcher(new GnewsSearch(),options);     这是资讯搜索  还有其他好多类,可以查看google的api
    searchControl.setResultSetSize(GSearch.LARGE_RESULTSET);    //显示多少个,只能是4个和8个。。。。。。。

    searchControl.draw(document.getElementById("searchcontrol"));
    searchControl.execute(searchStr);
  }
    //GSearch.setOnLoadCallback(OnLoad);
function Search()
{
    OnSearchLoad(document.all.searchKey.value);
}

function GetResult(searcher)
{

    var strContent = "";
    if( searcher.results && searcher.results.length>0)
    {
    for(var i=0;i<searcher.results.length;i++)
    {
        var result = searcher.results[i];
        strContent += "<br />"+result.title+"<br />来自:"+result.publisher+"&nbsp;<a href='"+result.unescapedUrl+"'>"+result.unescapedUrl+"</a><br />" +result.content+"<br />——"+result.publishedDate +"<br />";
       
    }
    }
    document.all.Div1.innerHTML = strContent;
}
        </script>

        关键词:
        <input type="text" id="searchKey" />&nbsp;<span onclick="Search()"><a href="javascript:Search()">搜索</a></span>
        <div id="searchcontrol" style="display: none;">
        </div>
        <div id="Div1">
        </div>
    </div>

Key的申请
http://code.google.com/apis/ajaxsearch/signup.html

你可能感兴趣的:(html,Blog,Google,资讯)