简体   繁体   中英

Stuck in Jsoup parsing Html

how can i get that textA, text B and text C seperately?

i have tried .Owntext buth it gives all of them.I need something that gives text between two unique named h3s.

  <div class="Example">
      <h3>A:</h3>
       TextA
      <h3>B:</h3>
       TextB
      <h3>C:</h3>
       TextC
  <\div>

This is almost a perfect answer for your question. It would look about like this:

Document doc = Jsoup.parse(str);
Element div = doc.select("div").first();

for (Node node : div.childNodes()) {
    if (node instanceof org.jsoup.nodes.TextNode) {
        System.out.println(node.toString();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM