Java HTML / XML How to - Select html tag by tag name and class








Question

We would like to know how to select html tag by tag name and class.

Answer

//  w w  w. j av  a  2s. c  o  m
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class Main {

  public static void main(String[] args) throws Exception {
    String URL = "http://www.your server.com";
    Document doc = Jsoup.connect(URL).get();

    String cheapest = doc.select("b.item-price").first().text();
    System.out.println(cheapest);

  }
}