开发者

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

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!


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?)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜