Search code examples
androidhtmlcleaner

How to extract text within tags in htmlcleaner or jSoup


I'm newbie to Android development, can't get to understand HtmlCleaner or jSoup basics.

I have a page, e.g.

<html><body>
....(large code here)....
<b>Hello World! </b> 
....(large code here)....
</body> </html>

How can I extract the words within <b>..</b> tags?


Solution

  • If you are trying to use Jsoup this should be pretty easy

    Document doc = Jsoup.connect("http://www.w3schools.com/tags/tag_b.asp").get();
    Element firstBoldElement = doc.select("b").first();
    System.out.println("Bold Text is : "+firstBoldElement.text());
    

    You will have to add proper Exception handling to the above code.