Exemple #1
0
  public static void main(String[] args) {
    try {
      UserAgent userAgent = new UserAgent();
      userAgent.visit("http://jaunt-api.com/examples/food.htm");

      Elements elements = userAgent.doc.findEvery("<div>"); // find all divs in the document
      System.out.println(
          "Every div: " + elements.size() + " results"); // report number of search results.

      elements = userAgent.doc.findEach("<div>"); // find all non-nested divs
      System.out.println(
          "Each div: " + elements.size() + " results"); // report number of search results.
      // find non-nested divs within <p class='meat'>
      elements = userAgent.doc.findFirst("<p class=meat>").findEach("<div>");
      System.out.println(
          "Meat search: " + elements.size() + " results"); // report number of search results.
    } catch (JauntException e) {
      System.out.println(e);
    }
  }
  public static void main(String[] args) {
    try {
      UserAgent userAgent = new UserAgent();
      userAgent.visit("http://jaunt-api.com/examples/signup.htm");
      Document doc = userAgent.doc;

      doc.fillout(
          "E-mail:", "*****@*****.**"); // fill out the (textfield) component labelled "E-mail:"
      doc.choose(
          "Account Type:", "advanced"); // choose "advanced" from the menu labelled "Account Type:"
      doc.fillout(
          "Comments:", "no comment"); // fill out the (textarea) component labelled "Comments:"
      doc.choose(
          Label.RIGHT,
          "No thanks"); // choose the (radiobutton) component right-labelled "No thanks"
      doc.submit("create trial account"); // press the submit button labelled 'create trial account'
      System.out.println(userAgent.getLocation()); // print the current location (url)
    } catch (JauntException e) {
      System.out.println(e);
    }
  }
  public static void main(String[] args) {
    try {
      UserAgent userAgent = new UserAgent();
      userAgent.visit("http://jaunt-api.com/examples/hello.htm");

      Elements elements =
          userAgent.doc.findEvery("<div|span>"); // find every element who's tagname is div or span.
      System.out.println("search results:\n" + elements.innerHTML()); // print the search results

      elements = userAgent.doc.findEvery("<p id=1|4>"); // find every p element who's id is 1 or 4
      System.out.println("search results:\n" + elements.innerHTML()); // print the search results

      elements =
          userAgent.doc.findEvery("< id=[2-6]>"); // find every element (any name) with id from 2-6
      System.out.println("search results:\n" + elements.innerHTML()); // print the search results

      elements =
          userAgent.doc.findEvery(
              "&lt;p>ho"); // find every p who's joined child text contains 'ho' (regex)
      System.out.println("search results:\n" + elements.innerHTML()); // print the search results
    } catch (ResponseException e) {
      System.out.println(e);
    }
  }