[Home] [Kuri] [Sysad] [Internet?] [Blog] [Java] [Windows] [Download] [Profile] [Flash] [+] |
% cd /some/where % unzip /foo/bar/googleapi.zip % cd googleapi % java -cp googleapi.jar com.google.soap.search.GoogleAPIDemo \ れじすとれーしょんきー search 検索したい文字列 Parameters: Client key = れじすとれーしょんきー Directive = search Args = 検索したい文字列 Google Search Results: ...後略 |
% java -cp googleapi.jar com.google.soap.search.GoogleAPIDemo \ れじすとれーしょんきー spell congraturations Parameters: Client key = れじすとれーしょんきー Directive = spell Args = congraturations Spelling suggestion: congratulations |
import com.google.soap.search.*; public class googletest { // my registration key private static final String key = "れじすとれーしょんきー"; public static final int MAXRESULT = 10; public static final int MAXEND = 100; public static int showResults(GoogleSearchResult result) { GoogleSearchResultElement[] elements = result.getResultElements(); int start = result.getStartIndex(); System.out.println("start=" + start + ", end=" + result.getEndIndex()); for(int i=0; i<elements.length; i++) { System.out.println(" " + (start+i) + " : " + elements[i].getTitle() + " / " + elements[i].getURL()); } return elements.length; } public static void doSearch(GoogleSearch search) { int index=0; try { while(true) { search.setStartResult(index); GoogleSearchResult result = search.doSearch(); //System.out.println(result.toString()); if(showResults(result) < MAXRESULT) { break; } index = result.getEndIndex(); if(index >= MAXEND) { break; } } } catch(GoogleSearchFault fault) { fault.printStackTrace(); } } public static void main(String arg[]) { GoogleSearch search = new GoogleSearch(); search.setKey(key); search.setLanguageRestricts("lang_ja"); search.setMaxResults(MAXRESULT); search.setInputEncoding("x-sjis"); search.setOutputEncoding("x-sjis"); //search.setSoapServiceURL("http://tamao:8880/"); for(int i=0; i |
POST / HTTP/1.0 Host: tamao Content-Type: text/xml; charset=utf-8 Content-Length: 852 SOAPAction: "urn:GoogleSearchAction" <?xml version='1.0' encoding='UTF-8'?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" \ xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" \ xmlns:xsd="http://www.w3.org/1999/XMLSchema"> <SOAP-ENV:Body> <ns1:doGoogleSearch xmlns:ns1="urn:GoogleSearch" \ SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <key xsi:type="xsd:string">れじすとれーしょんきー</key> <q xsi:type="xsd:string">検索したい文字列</q> <start xsi:type="xsd:int">0</start> <maxResults xsi:type="xsd:int">10</maxResults> <filter xsi:type="xsd:boolean">true</filter> <restrict xsi:type="xsd:string"></restrict> <safeSearch xsi:type="xsd:boolean">false</safeSearch> <lr xsi:type="xsd:string">lang_ja</lr> <ie xsi:type="xsd:string">x-sjis</ie> <oe xsi:type="xsd:string">x-sjis</oe> </ns1:doGoogleSearch> </SOAP-ENV:Body> </SOAP-ENV:Envelope> |
[Home] [Kuri] [Sysad] [Internet?] [Blog] [Java] [Windows] [Download] [Profile] [Flash] [-] | |
usu@usupi.org | Last modified : Fri Jun 28 00:55:19 2002 |