我已使用beta version of the Bing Web Search API更新了我之前创建的以下代码段,以使用newer domain name: api.cognitive.microsoft.com/bing/v5.0/search <{3}}现在使用的 -
请替换您自己的Bing API密钥以运行示例
<!DOCTYPE html>
<html>
<head>
<title>Bing Search v5 - show all results</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<script>
var total;
var ofst = 0;
var pgcnt=50;
var results = '';
var burl = "https://api.cognitive.microsoft.com/bing/v5.0/search/?q=Bill Gates&count=" + pgcnt + "&offset=" + ofst + "&mkt=en-us&freshness=Month"; //737 results
//var burl = "https://api.cognitive.microsoft.com/bing/v5.0/search/?q=Bill Gates&count=" + pgcnt + "&offset=" + ofst + "&mkt=en-us"; //304 results
//var burl = "https://api.cognitive.microsoft.com/bing/v5.0/search/?q=site:mvark.blogspot.com&count=" + pgcnt + "&offset=" + ofst + "&mkt=en-us&freshness=Month";
$(function() {
function xhr_get(url) {
return $.ajax({
url: url,
beforeSend: function(xhrObj){
// Request headers
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","abc123"); //replace value with your own key
},
type: "GET",
})
.done(function(data) {
total = data.webPages.totalEstimatedMatches;
len = data.webPages.value.length
for (i=0; i<len; i++ )
{
results += "<p><a href='" + data.webPages.value[i].url + "'>" + data.webPages.value[i].name + "</a>: " + data.webPages.value[i].snippet + "</p>";
}
$('#content').html(results);
ofst += pgcnt;
if (total > ofst) {
burl = "https://api.cognitive.microsoft.com/bing/v5.0/search/?q=Bill Gates&count=" + pgcnt + "&offset=" + ofst + "&mkt=en-us&freshness=Month";
//burl = "https://api.cognitive.microsoft.com/bing/v5.0/search/?q=Bill Gates&count=" + pgcnt + "&offset=" + ofst + "&mkt=en-us";
//burl = "https://api.cognitive.microsoft.com/bing/v5.0/search/?q=site:mvark.blogspot.com&count=" + pgcnt + "&offset=" + ofst + "&mkt=en-us&freshness=Month";
xhr_get(burl);
}
else { console.log('No more results to show');
}
})
}
xhr_get(burl);
});
</script>
Results: <div id="content">Fetching...</div>
</body>
</html>
&#13;
我看到之前返回的结果与结果现在取得了。我想知道我的代码是否有问题导致更改的行为以及以下内容的答案:
答案 0 :(得分:1)
500 < totalEstimatedMatches < 2000
。他们如何评估&#39;此编号不在文档中。 &responseFilter=Webpages
添加到您正在制作的所有网址的末尾。列出您的回复时,您似乎只计算了网络结果,但没有指定查询只返回网络结果。