| Real'sHowTo |
|
|
Custom Search
|
| Real'sHowTo |
|
|
Custom Search
|
You need to fool Google by pretending to be a legitimate browser.
String search= "What you want to search for"; String google="http://www.google.ca/search?q=" + search + "&hl=en&ie=UTF-8&oe=UTF8"; URL urlObject = new URL(google); URLConnection con = urlObject.openConnection(); con.setRequestProperty ( "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" ); webData = new BufferedReader(new InputStreamReader(con.getInputStream())); ...
As seen above, you can directly override the HTTP header. Another way is to start the program with a modified System.property http.agent.
>java "-Dhttp.agent=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" MyClass
System.setProperty
("http.agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
Written and compiled by Réal Gagnon ©1998-2013
[ home ]