问题描述
我能够连接并设置必应自定义搜索。 我的问题是如何获得以下 10 个结果? 一个请求是否可以得到 10 个以上的结果?
var subscriptionKey = "My Key";
var customConfigId = "My ID";
var searchTerm = "test";
var url = "https://api.bing.microsoft.com/v7.0/custom/search?q=" + searchTerm + "&customconfig=" + customConfigId + "&mkt=en-US";
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];
}
解决方法
有一个 count
查询参数默认为 10
要分页,请使用 offset
,增量为 count
参考文档 - https://docs.microsoft.com/en-us/bing/search-apis/bing-custom-search/quickstarts/rest/csharp