posts - 97,  comments - 93,  trackbacks - 0
          昨晚同學(xué)找我?guī)兔懸粋€利用GOOGLE API的小程序,也比較感興趣所以就應(yīng)下了。下載了GOOGLE提供的googleapi.jar,大約花了20多分鐘,寫了這個小程序,由于需要提供GOOGLE key所以也懶得去申請,就沒有測試~~呵呵
          (原來本來一直用netbeans,:),主要是因?yàn)樽觯螅酰畹男@大使,現(xiàn)在用eclipse了:),原因也很簡單,是因?yàn)橐剑桑拢蛯?shí)習(xí)了,不過說實(shí)話它們確實(shí)都各有各的長處,這里呢用eclipse作的了)。
          目錄結(jié)構(gòu)很簡單   


          類實(shí)現(xiàn)主要為:
          *******************
          GSTest.java
          *******************
           1 import com.google.soap.search.*;
           2 
           3 /**
           4  * @author QuQiang
           5  * creat a google search object,and return a set of the search reasult
           6  */
           7 
           8 public class GSTest {
           9 
          10     private String key=ReadPro.getResource("GoogleKeycode");
          11     private String searchContent=ReadPro.getResource("SearchContent");
          12     
          13     GoogleSearch GsTest = new GoogleSearch();
          14     
          15     public GoogleSearchResult SearchResult(){
          16         GsTest.setKey(key);
          17         GoogleSearchResult GSR = new GoogleSearchResult();
          18         try {
          19             GsTest.setQueryString(searchContent);
          20             GSR = GsTest.doSearch();
          21         } catch (GoogleSearchFault e) {
          22             e.printStackTrace();
          23         }
          24         return GSR;
          25     }
          26 }
          *******************
          ReadPro.java
          *******************
           1 package sun.org.nicky.myorgtest;
           2 
           3 /**
           4  * @author QuQiang
           5  *
           6  */
           7     import java.io.InputStream;
           8     import java.io.IOException;
           9     import java.util.Properties;
          10 
          11     public class ReadPro{
          12        private static Properties property = null;
          13       
          14        static{
          15           InputStream stream = null;
          16           try{
          17             stream=ReadPro.class.getResourceAsStream("/resource/app.property");
          18             property = new Properties();
          19             property.load(stream);
          20           }catch(IOException e){
          21               e.printStackTrace();
          22           }finally{
          23               if(stream != null){
          24                  try{
          25                     stream.close();
          26                  }catch(IOException e){
          27                     e.printStackTrace();
          28                  }           
          29               }
          30           }
          31        }
          32        public static String getResource(String key){
          33          if(property == null){
          34            return null;// init error;
          35          }
          36          
          37          return property.getProperty(key);
          38        }
          39     }
          *******************
          Main.java
          *******************
           1 package sun.org.nicky.myorgtest;
           2 
           3 import java.io.File;
           4 import java.io.FileNotFoundException;
           5 import java.io.FileOutputStream;
           6 import java.io.PrintStream;
           7 
           8 import com.google.soap.search.GoogleSearchResult;
           9 import com.google.soap.search.GoogleSearchResultElement;
          10 
          11 /**
          12  * @author QuQiang Main function
          13  */
          14 public class Main {
          15     private static File file = new File("search.html");
          16 
          17     public static void main(String[] args) {
          18         GSTest newOGST = new GSTest();
          19         GoogleSearchResult newOGSTR = newOGST.SearchResult();
          20         GoogleSearchResultElement[] GSTRArray = new GoogleSearchResultElement[newOGSTR
          21                 .getResultElements().length];
          22         FileOutputStream fs = null;
          23         PrintStream p = null;
          24         try {
          25             fs = new FileOutputStream(file);
          26             p = new PrintStream(fs);
          27             p.append("<!--Result Returned by Google Search Engine-->\n");
          28             for (int i = 0; i < GSTRArray.length; i++) {
          29                 p.append(GSTRArray[i].toString());
          30                 System.out.println(GSTRArray[i].toString());
          31             }
          32         } catch (FileNotFoundException e) {
          33             e.printStackTrace();
          34         } finally {
          35             p.close();
          36         }
          37     }
          38 }
          至于 app.property就更簡單了,不過key需要自己填
          1 GoogleKeycode        = ******
          2 SearchContent        = ******



          posted on 2007-04-14 15:22 wqwqwqwqwq 閱讀(3567) 評論(9)  編輯  收藏 所屬分類: Simple Java

          FeedBack:
          # re: 利用google api寫的小程序 
          2007-11-04 18:45 | 風(fēng)中之歌
          google里找不到那個googleapi.jar,能傳我一個嗎?
          sakura-2008@163.com
          萬分感謝!  回復(fù)  更多評論
            
          # re: 利用google api寫的小程序 
          2008-01-10 22:54 | wangli
          您好,也能否傳我一個啊?rcwangli@126.com謝謝了。  回復(fù)  更多評論
            
          # re: 利用google api寫的小程序 
          2008-01-12 21:30 | nicky
          都已經(jīng)發(fā)給你們了
          現(xiàn)在據(jù)說google已經(jīng)不再提供那個的key的申請了,我想有四個考慮的方式
          第一,這并不說明,原來別人申請的不會奏效。
          第二,大家也可以使用其他的比如baidu yahoo的搜索結(jié)果。
          第三,你可以使用非ws的方式獲取,比如socket,但是要注意連接的ip,時間次數(shù),服務(wù)器也是很聰明的^^。
          第四,按步就搬咯,去google code lab之類的去研究下它現(xiàn)在提供給自由開發(fā)者的解決方案。
          一己之見,有待補(bǔ)充。
            回復(fù)  更多評論
            
          # re: 利用google api寫的小程序 [未登錄]
          2008-01-14 11:00 | libin
          我要用這個搜索result的數(shù)目做實(shí)驗(yàn),
          但是現(xiàn)在新的版本好像不提供這個接口了
          老版本的提供嗎?
          請指教
          我的郵箱是wbreadlee@gmail.com麻煩發(fā)給我好嗎? 還有那個key  回復(fù)  更多評論
            
          # re: 利用google api寫的小程序 
          2008-01-21 13:03 | rcwangli
          我?guī)滋鞗]打開郵箱了,覺得沒有人會理會我,今天一打開竟然收到了,太謝謝了,贊一個^^  回復(fù)  更多評論
            
          # re: 利用google api寫的小程序 
          2008-01-23 15:59 | monke82
          麻煩也發(fā)一個給我吧,謝謝了阿。
          monke82@163.com  回復(fù)  更多評論
            
          # re: 利用google api寫的小程序 
          2008-01-29 01:48 | kefon
          可不可以也給我一個?kefon@163.com 謝謝  回復(fù)  更多評論
            
          # re: 利用google api寫的小程序 
          2008-03-18 16:08 | dustin.xu
          如果可以,能否也給我一個key,畢設(shè)需要,搜了group兩天也沒找到,就快崩潰了
          dustin.xu@gmail.com  回復(fù)  更多評論
            
          # Seo News
          2009-05-18 20:53 | Seo News
          Give please. Inspiration does exist, but it must find you working.
          I am from Zambia and , too, and now am writing in English, give true I wrote the following sentence: "Discover performance based seo services.Left, bullet seo optimization, right."

          THX :-D, Wilford.  回復(fù)  更多評論
            
          <2008年1月>
          303112345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789




          常用鏈接

          留言簿(10)

          隨筆分類(95)

          隨筆檔案(97)

          文章檔案(10)

          相冊

          J2ME技術(shù)網(wǎng)站

          java技術(shù)相關(guān)

          mess

          搜索

          •  

          最新評論

          閱讀排行榜

          校園夢網(wǎng)網(wǎng)絡(luò)電話,中國最優(yōu)秀的網(wǎng)絡(luò)電話
          主站蜘蛛池模板: 金堂县| 水城县| 任丘市| 盐源县| 汉源县| 安溪县| 偏关县| 民勤县| 池州市| 大化| 通榆县| 汉中市| 新疆| 通化市| 博湖县| 浙江省| 富锦市| 林甸县| 白城市| 固阳县| 翁牛特旗| 五河县| 建平县| 定安县| 金华市| 阳山县| 新竹县| 柞水县| 宁陵县| 赣州市| 大港区| 改则县| 怀宁县| 洛川县| 辽阳县| 祁门县| 金沙县| 秦安县| 时尚| 磐安县| 凤城市|