Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class Main {
    public static void main(String[] args) {
        String html = "<html>                        " + "  <body>                      "
                + "    <table id='myTable'>      " + "      <tbody>                 "
                + "        <tr>                  " + "          <th>header</th>     "
                + "          <td>1</td>          " + "            <table>           "
                + "              <tbody>         " + "                <tr>          "
                + "                  <td>a1</td> " + "                  <td>a2</td> "
                + "                  <td>a3</td> " + "                </tr>         "
                + "              </tbody>        " + "            </table>          "
                + "          </td>               " + "          <td>high level2</td>"
                + "          <td>high level3</td>" + "        </tr>                 "
                + "      </tbody>                " + "    </table>                  "
                + "  </body>                     " + "</html>                       ";
        Document doc = Jsoup.parse(html);
        Elements highLevelTDs = doc.select("#myTable > tbody > tr > td");
        System.out.println(highLevelTDs.size());
        for (Element td : highLevelTDs) {
            System.out.println(td);
        }
    }
}