Rectangle 27 0

jsoup how to read html tag with values in java?


#root:
    <html>
     <head></head>
     <body>
      <div class="main">
       <div class="sub">
         sub 
       </div>main 
      </div>
     </body>
    </html>
    ---
    html:
    <html>
     <head></head>
     <body>
      <div class="main">
       <div class="sub">
         sub 
       </div>main 
      </div>
     </body>
    </html>
    ---
    head:
    <head></head>
    ---
    body:
    <body>
     <div class="main">
      <div class="sub">
        sub 
      </div>main 
     </div>
    </body>
    ---
    div:
    <div class="main">
     <div class="sub">
       sub 
     </div>main 
    </div>
    ---
    div:
    <div class="sub">
      sub 
    </div>
    ---
String html="<html><body><div class=\"main\">" + "<div class=\"sub\"> sub </div>" + "main </div></body></html>";
    Document doc=Jsoup.parse(html);
    Elements divs=doc.select("*");
    for(Element div : divs){
        System.out.println(div.tag() + ":\n" + div.toString());
        System.out.println("---");
    }

I guess what you want to do is to show each tag name and the content in it. The sample code is like this.

Note