HTML Java



  • There is a text:

    <p>текст1</p>
    <p>текст2</p>
    <img ...><br>
    <p>текст3</p>
    <img ...><br>
    

    And so on. ♪

    We need to draw up a list, every element of which is the line between the image tags, that is, one line-- текст1 + текст2second line текст3♪ I don't want to do it in hand, and how do I do it with passers or regulars, I haven't figured it out yet.



  • Use the library. https://jsoup.org/download

    Document doc = Jsoup.parse(new File("files/file.html"), "UTF-8");
    for(Element element : doc.getAllElements()) {
        if(element.tagName().equals("p")) System.out.print(element.text() + " ");
        else if(element.tagName().equals("img")) System.out.println();
    }
    

    Conclusion

    text1
    text3




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2