简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM