我在网站上使用Google Search API来生成网站的结果。(the site)问题是,它根本没有产生结果。如果我将站点限制更改为其他站点(例如wikipedia.org或其他任何站点),则会产生结果。
并非该网站未列出 - 当我在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);
答案 0 :(得分:0)
您是否尝试从setSiteRestriction
删除HTTP部分? Google文档似乎使用约定setSiteRestriction("domain.com")
而没有任何协议: