ok, i've manage to do it with Jsoup, thanks phi.lho.
i publish the code as i didn't found an example using it with processing.
The code get the search page from yahoo and print the search results:
- import org.jsoup.Jsoup;
- import org.jsoup.helper.Validate;
- import org.jsoup.nodes.Document;
- import org.jsoup.nodes.Element;
- import org.jsoup.select.Elements;
- import java.io.IOException;
- void setup() {
- //the page i want load
- String url = "http://search.yahoo.com/search?p=processing.org";
-
- println("Fetching %s..." + url);
- Document doc;
- //there's an unhandled exception in the library, so we must use try-catch
- try {
- doc = Jsoup.connect(url).get();
- }
- catch (Exception e) {
- println(e);
- doc = null;
- }
- //get only <a> tag under <h3> (the search results in yahoo)
- Elements test = doc.select("h3 > a");
-
- //print it out
- println("-------------");
- for (Element t : test) {
- println(t.text()+" | "+t.attr("abs:href"));
- }
- }
any suggestion to improve it is welcome.
Anyway, i have a problem using it with google.
if you run the same code with the url "http://www.google.com/search?q=processing.org", it returns this error:
Exception in thread "Animation Thread" java.lang.NullPointerException
at jsoup_test.setup(jsoup_test.java:52)
at processing.core.PApplet.handleDraw(PApplet.java:1608)
at processing.core.PApplet.run(PApplet.java:1530)
at java.lang.Thread.run(Thread.java:680)
any suggestion?