Google Open WebServices Query Interface

zhaozj2021-02-11  167

The king of finding the engine google opened its query interface in 4/11, allowing Java and .NET programmers around the world to find instructions for Google, and can use the results in their own Program or web pages. However, there is also a restriction on the use. It only allows unpaid programmers to find 1000 times a day. Before you use, you must first register your account to get a 32-bit length License Key. When you call the query, you must use this license key to use. Because WebServices describes the open interface in WSDL (Web Service Definition Language), the walking communication agreement is SOAP ON HTTP, so it is theoretically through the firewall.

The Java sample program is as follows: import java.io. *; import com.google.soap.search. *; // This is Googleapi.jar, supplied by Google Public Class searchGoogle {public static void main (String [] args) { IF (args.length! = 2) {system.err.println ("USAGE: Java Searchgoogle Licensekey Query String"); System.exit (1);} String ClientKey = args [0]; string querystring = args [1 ]; System.out.println ("Query String =" queryString); // Generate a lookup object, set output encoding (BIG5) Googlesearch S = New Googlesearch (); s.setKey (ClientKey); s.setOutputencoding "BIG5"); try {s.setQueryString (qyeryString); GoGlesearchResult r = s.dosearch (); system.out.println ("Find Result:"); system.out.println ("======= ================ "); System.out.Println (R.Tostring ());} catch (goagleasearchfault e) {system.out.println (" Find failed "; }}} Usage and Query Results (Execute Environment: Linux JDK 1.3.1_01, the host is located behind the firewall): java -classpath.: ../ lib / googleapi.jar searchGoogle xxxxxxxx- My LicenseKey-xxxxxxxx Linuxfab query character String = Linuxfab lookup results: ====================== {TM = 0.048257 q = "Linuxfab" CT = "TT =" "" "" "" "" "" "" "" "" "" "" "" "" = "B ig5 ", FVN =" Top / World / Chinese_Traditional / computer / Operating_Systems / Unix / Linux "}} Start Index = 1 End Index = 10 Estimated Total Results Number = 11500 Document Filtering = true Estimate Correct = false Rs = {[URL = "http://bbs.ee.ntu.edu.tw/boards/linux/21/" Title = "◆ [Linuxfab Morning Post]" Snippet = "

◆ [Linuxfab Morning Post] ... 5, ◇ [Linuxfab this week column] How to make simple floppy liunx, Linuxfab. 07/13/01. ... "Directory Category = {SE =" ", fvn ="} Directory title = "" Summary = "" Cached size = "11k" related information present = true host name = ""], [url = "http://bbs.e.ntu.edu.tw/boards/linux/21 /73.html "Title =" ◇ [Linuxfab Morning Post] - Linux 2.4.10 The illegal ┅ ┅ "Snippet =" ◇ [Linuxfab Monument] - Linux 2.4.10 The illegal blister is ┅. Sender: Linuxfab.bbs. "Directory Category = {SE =" "" ""} Directory Title = "" Summary = "" Cached size = "10k" Related Information Present = True Host Name = "bbs.ee.ntu.edu.tw "], [Url =" http://www.lslnet.com/linux/docs/linux-3033.htm "title =" Linuxfab: Red Hat7.0? New features - [? Forest - free? Piece] "Snippet = "... Linuxfab: Red Hat7.0? New features? Forest http://www.lslnet.com, September 24, 2000 09:59 ... Excerpted from: http: linuxfab.cx [?? window]. ... "Directory Category = {SE =" "" "" "} Directory Title =" "Summary =" "Cached size =" 5K "related information present = true host name =" "], if of course, output The result is not so messy, G The API provided by OOGLE has a variety of findings, such as starting from the first few starts, setting back the number, preference lookup (avoid looking for the result of the coffee when Java) ... Wait, you can be good It's fun to play. If you don't want to use Google's library, you can also use your WEBSERVICES toolproof, automatically capture the WSDL documentation provided by Google (at: http://api.google.com/googlesearch.wsdl), and generate related Java Object.

The following set of Java WebServices with GLUE software package to do an example: $ wsdl2java http://api.google.com/GoogleSearch.wsdl -p example -d example / write file example / IGoogleSearchPort.java write file example / GoogleSearchServiceHelper.java write file example / ResultElement.java write file example / DirectoryCategory.java write file example / strengths GoogleSearchResult.java write file GoogleSearchService.map GLUE is that it automatically for you to handle all XML <-> Java Object Mapping and SOAP transport problems, and you do not even You don't need to understand WSDL, you can use WebServices directly! We have now converted WSDL to Java objects, and the package is called Example, which is written in the client to connect Google: Import java.io.registry; // is included in glue-std.jar, Glue Standard Edition library. *; // Glue Automatically generates the Java object generated by WSDL public class searchGoogle2 {public static void main (string [] args) {if (args.length! = 2) {system. Err.Println ("USAGE: Java Searchgoogle LicenseKey Query String"); System.exit (1);} String ClientKey = args [0]; string queryString = args [1]; system.out.println ("query string = " queryString); string url =" http://api.google.com/googlesearch.wsdl "; try {// uses Glue generated interface, go to Bind Google's WSDL IGOOGLESEARCHPORT Searcher = (Igooglesearchport) Registry.bind ( URL, Igogledgearchport.class; // Query GooglesearchResult Result = Searcher.dogooglesearch (ClientKey, QueryString, 0, 1, False, "", False, "BIG5", "BIG5"); System.out.Println "Find results:"); system.out.println ("========================"); system.out.println ("response quantity:" Result.ResulTelements.Length; System.out.println ("first Result: "); system.out.println ("

Introduction: " Result.ResulTelements [0] .summary); System.out.println (" URL: " Result.ResulTelements [0] .url); System.Out.println (" Segment: " Result.ResulTelements [ 0]. Snippet; system.out.println ("header:" result.resultelements [0] .title; system.out.println ("host:" result.resultelements [0] .hostname); System .out.println ("directory:" result.resultelements [0] .directorytitle;} catch (electric.registry.registryException e) {system.out.println ("error:" E.getMessage ());} }} The execution result is as follows: $ java -classpath.: ../ LIB / GLUE-std.jar: ../ lib / j2ee.jar: ../ lib / jnet.jar searchgoogle2 xxxxxxxxx - My LicenseKey-xxxxxxxxxxxxfab Query string = linuxfab lookup results: ====================== Response Quantity: 1 First result: Introduction: URL: http://bbs.ee .nTu.edu.tw / Boards / Linux / 21 / Fragment: ◆ [Linuxfab Morning Post] ... 5, ◇ [Linuxfab this week column] How to make simple floppy liunx, Linuxfab. 07/13/01. ... Header: ◆ [Linuxfab Morning Post] Host: Directory: To note, this is just the Google Beta2 version of WSDL, the future interface will be fade, and the remote host (API.google.com) is still less stable, Sometimes I will not be in the past, sometimes INTERNAL Server Error's error. However, the above introduction should give you a simple WebServices out Read it? At present, almost all program languages ​​have WebServices's related software packs, whether you are a PHP web maker, or a VB window programmer, you should find the related software package, write the WebServices of WebServices directly on your webpage / program and Server. Dipout message: The world's largest online bookstore Amazon, also begins to provide the WebServices interface to the agent (Associates, you can place an ICON or link to Amazon on your personal page, thereby earning part of the transaction amount). Since the agent now uses the WebServices provided by Amazon to write a web / desktop application! It seems that similar WebServices will gradually be used in many large sites, perhaps Linuxfab / Sourcefab can consider introducing this technology, making this site a network operation center of the Chinese Open Source.

References google web APIS O'Reilly Network: Google Web API [April 21, 2002] 'author: smallufo

转载请注明原文地址:https://www.9cbs.com/read-5770.html

New Post(0)