Jsoup Java HTML Parser Tests

The JUnit tests in Jonathan Hedley's JSoup Repository are an excellent resource for learning JSoup and seeing it in action.

Here's some example code:

@Test public void testAllElements() {
    String h = "<div><p>Hello</p><p><b>there</b></p></div>";
    Document doc = Jsoup.parse(h);
    Elements allDoc = doc.select("*");
    Elements allUnderDiv = doc.select("div *");
    assertEquals(8, allDoc.size());
    assertEquals(3, allUnderDiv.size());
    assertEquals("p", allUnderDiv.first().tagName());


Posted April 05, 2017 03:09 PM EDT

More Like This Post