我正在尝试实现一个需要谷歌网络搜索API的元搜索引擎。我正在尝试在java脚本中实现Google网络搜索API。但我得到的结果不超过 4 个。
以下是代码:
<HTML>
<HEAD>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script src="http://www.google.com/jsapi? type="text/javascript"></script>
<script type="text/javascript">google.load('search','1');</script>
<TITLE>Quick Data Search</TITLE>
</HEAD>
<body>
<div id="page-wrap">
<div style="height:30px"></div>
<center>
<input type="text" title="Quick Data Search" id="searchbox" name="searchbox"/>
</center>
<br/><br/>
<div id="search-content">
<div class="content" style="width:400px; display:inline">
<div class="header">Web</div>
<div class="data" id="web-content"></div>
</div>
</div>
</body>
<SCRIPT>
var webSearch;
var lastSearch=0;
$(function()
{
webSearch=new google.search.WebSearch();
webSearch.setSearchCompleteCallback(this,webSearchComplete,[webSearch,lastSearch]);
var hash=window.location.hash;
if(hash!=""&&hash.length>0){
if(hash.substr(0,3)=='#q='){
var query=hash.substr(3,hash.length-3);
$('#searchbox').removeClass('text-label').val(query);
search(query);
}
}
$('#searchbox').focus();});
function webSearchComplete(searcher,searchNum){
var contentDiv=document.getElementById('web-content');
contentDiv.innerHTML='';
var results=searcher.results;
var newResultsDiv=document.createElement('div');
newResultsDiv.id='web-content';
for(var i=0;i<results.length;i++){
var result=results[i];
var resultHTML='<div style="height:70px; margin-top:5px;">';
resultHTML+='<a href="'+result.unescapedUrl+'" target="_blank">
<b>'+result.titleNoFormatting+'</b></a><br/>'+result.content+'<div/>';
newResultsDiv.innerHTML+=resultHTML;
}
contentDiv.appendChild(newResultsDiv);
}
$('#searchbox').keyup(function(){
var query=$(this).val();search(query);
});
function search(query){
if(query.length>0){
$("#search-content").show();
document.title=query+" | Quick Data Search";
window.location.hash="q="+query;
}
else{
document.title="Quick Data Search ";$("#search-content").hide();
}
webSearch.execute(query);newsSearch.execute(query);
}
$('#searchbox').each(function(){
$(this).addClass('text-label');
$(this).keyup(function(){
if(this.value.length==1){
$(this).removeClass('text-label');
}
if(this.value==''){
$(this).addClass('text-label');
}
});
});
</SCRIPT>
请帮忙。
请尝试以下代码
<script src="//www.google.com/jsapi?rsz=[results]"></script>
[结果] - 范围从 1 到 8 的数字 - 要返回的结果数