问题
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