How can I limit the number of returned Google search results in this C# program?

妖精的绣舞 提交于 2019-12-24 07:56:43

问题


I just want to return four results with the following C# snippet. How can I accomplish this? I know I could probably just parse the returned results, but I'd rather just grab only four to begin with, if that's possible.

var searchTerm = "pizza boxes";
        using (var web = new WebClient())
        {
            web.Headers.Add("Referrer", "http://localhost:49360/");
            var result = web.DownloadString(String.Format(
                   "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q={0}",
                   searchTerm));
            Console.WriteLine(result);
        }

Thanks in advance for any help!


回答1:


Based on this documentation it looks like you could just put

rsz=4

in the URL.

Note that although I work for Google, I have no experience in these APIs, and this answer should be seen as a personal one, and not associated with Google :)

(I further note that the API has been deprecated. Have you looked at moving to the custom search API instead?)




回答2:


Think you have two parameters you can set:

start=1;
rsz='large' 

The rsz value can set to small or large, small will fetch 4 results and large will fetch 8 results.

start value can be set as any other integer to start from that particular row.



来源:https://stackoverflow.com/questions/4212408/how-can-i-limit-the-number-of-returned-google-search-results-in-this-c-sharp-pro

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!