We all know the search capabilities of the famous search engine magnate Google. I personally think that if you cannot search by Google, there is basically no other possibility.
I also like it! We also want to use all of its powerful functions to serve our system. Google provides us with Api details.
Http://www.google.com/apis/check it out! Next I would like to briefly explain how to use IT (very simple, don't laugh at me ).
First, you should apply for an account at google! With this account, you can use WebService, but one account can only use 1000 times a day! I think
Enough.
Next, we can add a Web reference in our project (select "project" in the menu to see "add Web reference...") and enter:
Click "refresh" after the http://api.Google.com/GoogleSearch.wsdl to see the wsdl file can be determined! As for what proxy VS has done for you :-)! In
Add the following reference using google.com. google. api to the namespace: DirectoryCategory, GoogleSearchResult,
GoogleSearchService and ResultElement. In the page class, we write private GoogleSearchService webService = null; a field in
It can be directly instantiated. For more information, see referenceceat http://www.google.com/apis.
Finally, it is used. First, we need to instantiate the object webService = new GoogleSearchService () where we use the service; in the four classes mentioned above
GoogleSearchResult is returned. We declare a GoogleSearchResult webResult = null; and use the following statement to search
Try {
WebResult = webService. doGoogleSearch (txtKey. Text, txtKeyword. Text, 0, 10, false, "", false ,"","","");
}
Catch (Exception ex ){
This. Response. Redirect ("Error. aspx? Info = "+ ex. Message );
}
Then we can use
ArrayList al = new ArrayList ();
String tmp = "";
For (int I = 0; I <webResult. resultElements. Length; I ++ ){
Tmp = "<a href = '" + webResult. resultElements [I]. URL + "'>" + webResult. resultElements [I]. title + "</a> ";
Al. Add (tmp );
}
This. grd. DataSource = al;
This. grd. DataBind ();
Write the result to an ArrayList, HashTable, or DataTable, and bind the result directly to the DataGrid!
Google also seems to have limited the number of searches to 10!
The above is nothing to do! Hope to help everyone and hope everyone can learn and make progress together!
The following are some webpages about Google api use. I think they are clearer than I can say!
Http://www.msdnaa.net/Resources/display.aspx? ResID = 1536.
Http://www.c-sharpcorner.com/Code/2002/Nov/GoogleSearch.asp
Http://www.msdnaa.net/Resources/Display.aspx? ResID = 2161.
Http://www.bbits.co.uk/Pubs/Articles/GoogleSearch.aspx
For the first time, please include more!
This article from the CSDN blog, reproduced please indicate the source: http://blog.csdn.net/21aspnet/archive/2004/10/30/160037.aspx