Johan_Wastring
YaBB Newbies
Offline
Posts: 28
Sweden
Re: Library for Yahoo BOSS Mashup?
Reply #1 - Oct 2nd , 2008, 9:29am
I made a quickfix for it myself with the Javcode found on Yahoo. I don't know Java, but this seemed to work. Hey, thanks Processing! You can only search with one word... uhm... not great, but still. Take it from here. It is a really dirty hack, but it works unless you test it extensively. It is not tested etc... I'm on a mac. If you get how to make decent queries (meaning more than one word :-) please post. I'm out of time here :-) Hope someone finds this helpful as a start... Here's the code: /* Quick and Dirty access to Yahoo Boss search More info on Yahoo Boss http://developer.yahoo.com/search/boss/ PRESS MOUSE AND THE SEARCH STARTS. The result is parsed via XML and printed to the console The querything is weird since it is a url - MEANING no empty spaces in the search... Anyone got a fix, welcome to post the fix for this. Probably found somewhere on developer.Yahoo.com. Not sure if you need a API-key, maybe this is the problem...? It works without this way... I said Quick and Dirty :-) */ import processing.net.*; import org.apache.commons.httpclient.*; import org.apache.commons.httpclient.methods.*; import java.io.*; import org.w3c.dom.*; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.xpath.*; String newSearch; int numSearches = 15; color white = #ffffff; void setup() { size(200, 200); } void draw() { background(white); } void mousePressed() { newSearch = "Processing"; try { searchIt("http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=" + newSearch + "&results=" + numSearches); } catch(Exception e) { e.printStackTrace(); } } void searchIt(String request) throws Exception{ HttpClient client = new HttpClient(); GetMethod method = new GetMethod(request); // Send GET request int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + method.getStatusLine()); } InputStream rstream = null; // Get the response body rstream = method.getResponseBodyAsStream(); // Process response Document response = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(rstream); XPathFactory factory = XPathFactory.newInstance(); XPath xPath=factory.newXPath(); //Get all search Result nodes NodeList nodes = (NodeList)xPath.evaluate("/ResultSet/Result", response, XPathConstants.NODESET); int nodeCount = nodes.getLength(); //iterate over search Result nodes for (int i = 0; i < nodeCount; i++) { //Get each xpath expression as a string String title = (String)xPath.evaluate("Title", nodes.item(i), XPathConstants.STRING); String summary = (String)xPath.evaluate("Summary", nodes.item(i), XPathConstants.STRING); String url = (String)xPath.evaluate("Url", nodes.item(i), XPathConstants.STRING); //print out the Title, Summary, and URL for each search result System.out.println("Title: " + title); System.out.println("Summary: " + summary); System.out.println("URL: " + url); System.out.println("--"); } }