I 've written an ASP .NET C# application using Visual Studio 2005 and
need to perform search queries for various phrases but without any GUI
elements. I've looked at many code examples but can't see how to do
Raw searches and get the results in a variable so I check them in the
result.
This is what I'm trying to mimic which I beleive is considered an
automated query which is a NO-NO!
The code below basically sends a Google search request for a phrase,
gets the reponse, looks for the ";swrnum" in the reponse and get the
number of search pages(hit count) for the phrase. Then I take that
number and use it within my application.
Please, any help is appreciated.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://
www.google.com/search?q=\"MY SEARCH PHRASE
\"&ie=UTF-8&oe=UTF-8&hl=nl&meta=");
// Set some reasonable limits on resources used by
this request
request.MaximumAutomaticRedirections = 4;
request.MaximumResponseHeadersLength = 4;
// Set credentials to use for this request.
request.Credentials =
CredentialCache.DefaultCredentials;
HttpWebResponse response = (HttpWebResponse)
request.GetResponse();
// Get the stream associated with the response.
Stream receiveStream = response.GetResponseStream();
// Pipes the stream to a higher level stream reader
with the required encoding format.
StreamReader readStream = new StreamReader
(receiveStream, Encoding.UTF8);
string returnedValue = readStream.ReadToEnd();
Regex rx = new Regex(";swrnum");
// Find a single match in the string.
Match m = rx.Match(returnedValue);
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google AJAX APIs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-ajax-search-api?hl=en
-~----------~----~----~----~------~----~------~--~---