Skip to content Skip to sidebar Skip to footer

Parsing Html Content Using Jsoup

This is my HTML source
  • 111
  • Solution 1:

    Try this for easy parsing using jsoup:

    // To parse the html pageDocumentdoc= Jsoup.connect("http://www.website.com").get();
    Documentdoc1= Jsoup.parse("<html><head><title>First parse</title></head>" + "<body> <p>Parsed HTML into a doc.</p></body></html>");
    
    Stringcontent= doc.body().text();
    
    // To get specific elements such as linksElementlinks= doc.select("a[href]");
    for(Element e: links){
        System.out.println("link: " + e.attr("abs:href"));
    }
    

    To learn more, visit Jsoup Docs

    Post a Comment for "Parsing Html Content Using Jsoup"