Google自定义搜索C#按日期筛选结果

时间:2018-10-19 01:39:14

标签: c# search google-custom-search

仅供参考...我对使用Google自定义搜索进行编码非常陌生。有没有人有过过滤Google自定义搜索结果的经验。我有一个前往Google并运行搜索的C#应用​​程序。我只想查看当天的结果。这可能吗?下面是我的代码。预先感谢!

    private static void Main(string[] args)
    {
        const string apiKey = "My Key";
        const string searchEngineId = "Search ID";
        const string query = "My Query";
        var customSearchService = new CustomsearchService(new BaseClientService.Initializer {ApiKey = apiKey});
        var listRequest = customSearchService.Cse.List(query);
        listRequest.Cx = searchEngineId;

        Console.WriteLine("Start...");
        IList<Result> paging = new List<Result>();
        var count = 0;
        while (paging != null)
        {
            Console.WriteLine($"Page {count}");
            listRequest.Start = count * 10 + 1;
            paging = listRequest.Execute().Items;
            if (paging != null)
                foreach (var item in paging)
                    Console.WriteLine("Title : " + item.Title + Environment.NewLine + "Link : " + item.Link +
                                      Environment.NewLine + Environment.NewLine);
            count++;
        }
        Console.WriteLine("Done.");
        Console.ReadLine();
    }

0 个答案:

没有答案