Search code examples
javahtmljsoup

How to select an element in Jsoup using its html content?


I want to select an element in Jsoup using its html content.

Example: LOCATION: 

How can i do it. I couldn't find any approriate selector methods directly. Is there any work around available?


Solution

  • Using Jsoup library you can parse from value from html using name, ID or class of element.

    String html = "<html><head><title>Title</title></head> <body><div id='location'>Mumbai, India</div></body></html>";
    Document document= Jsoup.parse(html);
    String content = document.getElementById("location").outerHtml();
    

    Happy Coding :-)