【问题标题】:How to get the next page of results from Bing Search Container in C#?如何从 C# 中的必应搜索容器中获取下一页结果?
【发布时间】:2014-11-18 20:46:39
【问题描述】:

我在 C# 中使用带有 Winform 的 BingSearchContainer.cs。我正在使用以下代码返回结果。看了好几个小时后,我不知道如何返回结果的其他页面。一次最多只能返回 50 个结果。我想返回更多页面,然后将它们添加到“imageSet”以获得结果图像的完整列表。任何提示或指针都会非常有用,在此先感谢您的帮助。

void bingSearch(string searchTerm)
        {
            try
            {
                imageSet = new List<Bing.ImageResult>();
                const string bingKey = "[key]";
                var bing = new BingSearchContainer(
                new Uri("https://api.datamarket.azure.com/Bing/Search/")) { Credentials = new NetworkCredential(bingKey, bingKey) };                
                var query = bing.Image("\"" + searchTerm + "\"" + "(" + site1 + " OR " + site2 + ")", null, null, null, null, null, ImageFilters);
                Debug.Print("Full Search: " + query.ToString());
                query = query.AddQueryOption("$top", 50);
                query = query.AddQueryOption("$skip", 20);
                var results = query.Execute();
                int index = 0;
                foreach (var result in results)
                {
                    imageSet.Add(result);
                    Debug.Print("URL: " + imageSet[index].MediaUrl);
                    index++;
                }
                Debug.Print("Results: " + imageSet.Count);
            }
            catch
            {
                Debug.Print("Error");
            }
        }

【问题讨论】:

    标签: c# winforms search bing


    【解决方案1】:

    解决了这个问题。

    其实很简单。 "$skip", 20 查询选项设置页面的偏移量,这样如果我的偏移量为 0,我将获得前 50 张图像,如果偏移量为 50,我将获得接下来的 50 张图像,依此类推。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 2020-06-27
      • 1970-01-01
      • 1970-01-01
      • 2017-09-13
      • 2016-04-02
      • 2012-04-10
      相关资源
      最近更新 更多