Re: Java example for displaying Google results?
Dale King wrote:
[...]
As has been discussed quite often lately, using the Google API is the
only legal way to do it. Anything else is a violation of the Google
terms of service.
[...]
import com.google.soap.search.*;
import javax.swing.JFrame;
public class formGoogleSearch extends JFrame {
/** Creates new form formGoogleSearch */
public formGoogleSearch() {
initComponents();
}
// Generated form and component code omitted
// ...
private void jButtonSearchMouseClicked
(java.awt.event.MouseEvent evt) {
try {
GoogleSearch s = new GoogleSearch();
s.setKey(jTextDevKey.getText());
s.setMaxResults(1);
s.setQueryString(jTextSearchTerm.getText());
GoogleSearchResult r = s.doSearch();
java.lang.String str =
r.getResultElements()[0].getSnippet();
str = str.replaceAll ("<b>", "");
str = str.replaceAll ("</b>", "");
str = str.replaceAll ("<br>", "");
jTextResult.setText(str);
}
catch (GoogleSearchFault f) {
jTextResult.setText("There has been a problem: "
+ f); }
}
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}
public static void main(java.lang.String[] args) {
new formGoogleSearch().show();
}
}
from:
Appendix C - Using the Google APIs with Java
Building Research Tools with Google for Dummies
by Harold Davis
John Wiley & Sons =A9 2005
Most of it is C# oriented, only the appendix is java centric :(
There's lotsa C# code which intrigues me, though, which, I imagine, can
be done in Java :)
-Thufir