You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ASP.NET C# 中Bing Custom Search获取后续10条结果及单请求条数问题

Bing Custom Search 分页查询与单请求返回条数设置方案

问题1:如何获取下一批10条搜索结果

  • 你需要在请求URL中添加offset参数,该参数表示要跳过的结果条数,默认值为0。
  • 首次请求默认返回前10条结果,需要获取下一批10条时,将offset设为10即可返回第11-20条结果,以此类推,下一次分页就将offset设置为20即可。
  • 可通过返回结果中的response.webPages.totalEstimatedMatches字段获取本次查询的总匹配结果数,设置的offset不要超过该数值,避免返回空结果。

问题2:单次接口请求是否支持返回超过10条的搜索结果

  • 支持,你可以通过count参数控制单次请求返回的结果条数。
  • 该参数有效值范围为1~50,默认值为10,最多单次可返回50条搜索结果。
  • 注意:即使你设置的count大于总匹配数,接口只会返回所有存在的匹配结果,不会额外填充空数据。

调整后的实现代码示例

var subscriptionKey = "My Key";
var customConfigId = "My ID";
var searchTerm = "test";
// 示例:单次请求返回20条结果,将count参数设为20即可;如果要获取第11-20条结果,设置offset=10、count=10即可
var url = $"https://api.bing.microsoft.com/v7.0/custom/search?q={searchTerm}&customconfig={customConfigId}&mkt=en-US&count=20&offset=0";

var client = new HttpClient();
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);

var httpResponseMessage = client.GetAsync(url).Result;
var responseContent = httpResponseMessage.Content.ReadAsStringAsync().Result;
BingCustomSearchResponse response = JsonConvert.DeserializeObject<BingCustomSearchResponse>(responseContent);

for (int i = 0; i < response.webPages.value.Length; i++)
{
    var webPage = response.webPages.value[i];
    // 此处添加搜索结果处理逻辑
}

内容的提问来源于stack exchange,提问作者Dany Maor

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.10 03:18:03