开发者

search word in google and want to find hits of each word using java program

I 开发者_StackOverflowhave 30000 dictionary words. In that I want to to search each word in Google and want to find hits of each word using Java program. Is it possible?


Look up <estimatedTotalResultsCount> using Google's SOAP search API. You'll be limited to 1000 queries per day though. This limit is removed if you use their AJAX API.


Since your duplicate post is closed, I'll post my answer here as well:

Whether this is possible or not doesn't really matter: Google doesn't want you to do that. They have a public AJAX-search API developers can use: http://code.google.com/apis/ajaxsearch/web.html


Here is a Sun tutorial on Reading to and Writing from an URLConnection.

The simplest URL I can see to make a Google search is like:

http://www.google.com/#q=wombat


Reading from a url with java is pretty straight forward. A basic working example is as follows

public Set<String> readUrl(String url) {

        String line;
        Set<String> lines = new HashSet<String>();

        try {
            URL url = new URL(url);
            URLConnection page = url.openConnection();

            BufferedReader in = new BufferedReader( new InputStreamReader(page.getInputStream()));

            while ((line = in.readLine()) != null) {
                lines.add(line);
            }

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return lines;
    }


I'd recommend separating your problem into pieces. Get each one working, then marry them together for the solution you want.

You have a few things going on here:

  1. Downloading text from a URL
  2. Scanning a stream of characters and breaking it up into words
  3. Iterating through a list of words and tallying up the hits from your dictionary

Computer science is all about taking large problems and decomposing them into smaller ones. I'd recommend that you start learning how to do that now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜