Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

google query

Thread view: 
Damo - 18 Nov 2006 14:10 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

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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.