diff options
author | Jagw <jagw@jagw.co.uk> | 2010-11-01 11:35:30 +0000 |
---|---|---|
committer | Jagw <jagw@jagw.co.uk> | 2010-11-01 11:35:30 +0000 |
commit | 1909f442ab2feb0f22694ab8573015e97061b4c2 (patch) | |
tree | 5beb7955a47753b3254561f7e2cf888a3ce98c41 |
Initial Commit of blasearch
-rw-r--r-- | blasearch.class | bin | 0 -> 1855 bytes | |||
-rw-r--r-- | blasearch.java | 73 |
2 files changed, 73 insertions, 0 deletions
diff --git a/blasearch.class b/blasearch.class Binary files differnew file mode 100644 index 0000000..bbed588 --- /dev/null +++ b/blasearch.class diff --git a/blasearch.java b/blasearch.java new file mode 100644 index 0000000..8baad91 --- /dev/null +++ b/blasearch.java @@ -0,0 +1,73 @@ +/* + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/* + Copyright 2010 Jamie Walters <jagw@jagw.co.uk> + based on code by Joe Robinson <joe@lc8n.com> +*/ + + +import java.net.URL; +import java.net.URLConnection; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; + +public class blasearch { + + public static void main(String[] args) throws IOException + { + String query = args[0]; + String[] parts = null; + //URL which provides XML response + URL url = new URL("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q="+ query); + + URLConnection urlc = url.openConnection(); + + BufferedReader br = new BufferedReader(new InputStreamReader(urlc.getInputStream())); + String line; + String[] lines; + ArrayList results = new ArrayList(); + ArrayList urls = new ArrayList(); + String result = ""; + String tempString = ""; + //Read every line + while ((line = br.readLine()) != null) + { + // Splits the google output by the commas + lines = line.split(","); + + for(int i=0; i<lines.length; i++){ + // Get the useful information (the urls!) + if(lines[i].startsWith("\"url\"")){ + tempString = lines[i]; + // Blat the non-url information + tempString = tempString.substring(7, tempString.length()-1); + results.add(tempString); + } + } + + } + // Print results + + if(results != null){ + for(int i=0; i<results.size(); i++){ + System.out.println(results.get(i)); + } + } + } + +} |