Demo program to use YQL.
The Yahoo Query Language can be used to search for a query the yahoo search engine and retireve the result.
first he user need to sign up for YQL to get the user key. Then used the program below to retrieve the results.
The below program returns the first 50 results (start=0 and count=50) is the format of xml(format=xml)
public static void main(String[] args) {
String query = "cricketer sachin tendulkar";
String API_KEY="xxxxx";//get your own key
URL url;
try {
query = URLEncoder.encode(query, "UTF-8");
url = new URL("http://boss.yahooapis.com/ysearch/web/v1/"+ query + "?appid=" + API_KEY + "&start=" + 0
+ "&count=50&format=xml");
URLConnection connection = url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(connection
.getInputStream()));
String inputLine = "";
while ((inputLine = in.readLine()) != null) {
System.out.println(query + " " + inputLine);
}
} catch (Exception e) {
e.printStackTrace();
}
}