I'm trying to query google using the URL class and appending the query
to the end of the URL :
Its returning no results, Anyone know why: this is what it looks like
public String google(String query)
{
String inputLine=null;
try {
URL google = new URL("http://www.google.com/search?q="+query);
BufferedReader d = new BufferedReader(new
InputStreamReader(google.openStream()));
while ((inputLine = d.readLine()) != null) {
System.out.println(inputLine);
}
d.close();
} catch (MalformedURLException me) {
System.out.println("MalformedURLException: " + me);
} catch (IOException ioe) {
System.out.println("IOException: " + ioe);
}
return inputLine;
}
thanks
Andrew Thompson - 18 Nov 2006 16:22 GMT
> I'm trying to query google
Google offers an API.
<http://code.google.com/apis.html>
..but..
> Its returning no results, Anyone know why: this is what it looks like
...
> URL google = new URL("http://www.google.com/search?q="+query);
..refuses connection to referers that identify
themselves as Java.
Use the API.
Andrew T.
Real Gagnon - 18 Nov 2006 18:58 GMT
> I'm trying to query google using the URL class and appending the query
> to the end of the URL :
> Its returning no results, Anyone know why: this is what it looks like
You need to fool Google by pretending to be a legitimate browser.
See http://www.rgagnon.com/javadetails/java-0399.html
Bye.

Signature
Real Gagnon from Quebec, Canada
* Looking for Java or PB code examples ? Visit Real's How-to
* http://www.rgagnon.com/howto.html