【发布时间】:2016-07-03 12:00:58
【问题描述】:
我更新了我之前使用beta version of the Bing Web Search API 创建的以下 sn-p 以使用newer domain name:api.cognitive.microsoft.com/bing/v5.0/search Bing Web Search API 现在使用 -
请替换您自己的 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>
我发现之前返回的结果与现在获取的结果之间存在差异。我想知道我的代码是否有问题导致行为改变以及以下问题的答案:
- 对于某些搜索关键字,我发现返回的最大结果现在正好是 1000 (totalEstimatedMatches=1000),但如果我通过 Bing 的网站进行搜索,结果会更多。 1000 是最大限制吗?是否有一些限制?
- 当添加 freshness=Month 请求参数时,它返回的结果比我不使用它时会得到的结果多吗?如果未指定新鲜度,默认行为不是获取所有结果吗?
【问题讨论】:
-
我发现可以找到的网页内容较少。其他人有同样的观察吗?
-
我不是 js 开发人员,但我正在用 python 写这个--> (github.com/rtruxal/py-cog-serv),当我复制你的第一个查询时,我得到的 totalEstimatedMatches 为 179000 而不是 737你的代码产生。不幸的是,这就是我所得到的。无法很好地阅读 JS,所以我无法识别问题。
标签: bing microsoft-cognitive web-search