How can I parse a HTML string in Java?

If you have a string which contains HTML you can use Jsoup library like this to get HTML elements:

String htmlTable= "<table><tr><td>Hello World!</td></tr></table>";
Document doc = Jsoup.parse(htmlTable);

// then use something like this to get your element:
Elements tds = doc.getElementsByTag("td");

// tds will contain this one element: <td>Hello World!</td>

Good luck!

Leave a Comment