以文本方式查看主题

-  课外天地 李树青  (http://www.njcie.com/bbs/index.asp)
--  信息检索原理课件  (http://www.njcie.com/bbs/list.asp?boardid=16)
----  编程访问Google搜索引擎的查询结果  (http://www.njcie.com/bbs/dispbbs.asp?boardid=16&id=492)

--  作者:admin
--  发布时间:2008/5/15 16:08:03
--  编程访问Google搜索引擎的查询结果

1、下载googleapi.jar,导入classpath路径,获取访问许可证号

 

2、代码为:

 

import com.google.soap.search.GoogleSearch;
import com.google.soap.search.GoogleSearchResult;
import com.google.soap.search.GoogleSearchFault;
import com.google.soap.search.GoogleSearchResultElement;

 

public class GoogleClient {

 

    public static void main(String[] args) {
        String keyword = "Java";
        String clientKey = "00000000000000000000000000";//请将其换成自己的许可证号
        GoogleSearch gs = new GoogleSearch();
        gs.setKey(clientKey);
        gs.setQueryString(keyword);
        gs.setLanguageRestricts("lang_zh-CN");
        gs.setStartResult(10);
        try {
            GoogleSearchResult gsr = gs.doSearch();
            GoogleSearchResultElement[] gsreList = gsr.getResultElements();
            for (int i = 0; i < gsreList.length; i++) {
                GoogleSearchResultElement gsre = gsreList;
                System.out.println("Title : " + gsre.getTitle());
                System.out.println("URL : " + gsre.getURL());
                System.out.println("Snippet: " + gsre.getSnippet());
                System.out
                        .println("----------------------------------------------------------");
            }
        } catch (GoogleSearchFault gsf) {
            System.out.println("The call to the Google Web APIs failed: "
                    + gsf.toString());
        }
    }

 

}

 

[此贴子已经被作者于2010-12-14 09:27:57编辑过]

--  作者:silvan
--  发布时间:2008/5/16 16:18:19
--  
老师:我找了好久都没找到googleapi.jar的下载入口。
--  作者:admin
--  发布时间:2008/5/17 18:06:00
--  回复

这个应该不难啊,你可以试一试自己的搜索方法

推荐一个:

http://debian.fmi.uni-sofia.bg/~hiena/googleapi/googleapi.jar


--  作者:silvan
--  发布时间:2008/5/18 22:27:29
--  

老师,请查看一下邮箱,我的问题发您邮箱里了