我在網站上使用Google搜索API來產生網站結果。(the site)問題是,它根本沒有產生結果。如果我將網站限制更改爲其他網站(例如wikipedia.org或任何其他網站),則會生成結果。谷歌搜索api沒有給出結果
這不是該網站沒有列出 - 當我在Google首頁上搜索site:www.hinroengineering.com
時,我得到了結果。
代碼如下:
google.load('search', '1');
function OnLoad() {
// Create a search control
var searchControl = new google.search.SearchControl();
// web search, open
options = new google.search.SearcherOptions();
options.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);
// Add in a WebSearch
var webSearch = new google.search.WebSearch();
// Restrict our search to pages from the current site only
webSearch.setSiteRestriction('http://www.hinroengineering.com');
webSearch.setUserDefinedLabel(" Search results ");
// Add the searcher to the SearchControl
searchControl.addSearcher(webSearch, options);
// tell the searcher to draw itself and tell it where to attach
searchControl.draw(document.getElementById("SeachContent"));
searchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);
// execute an inital search
searchControl.execute(CurrentSearchTerm);
//alert(webSearch.results.length);
}
google.setOnLoadCallback(OnLoad);
可不可以給你是如何作出這一呼籲一些細節?例如,撥打電話的確切代碼行會有幫助 – 2009-12-30 11:48:18
@james:這是你要求的,還是我發佈了錯誤的部分? – ZX12R 2009-12-30 11:52:44