JSoupTextExtractor implements HtmlTextExtractor { @Override public String getPlaintext(final String htmltext) { try { String hhtmltext = _end_prgrph_ptrn.matcher(htmltext).replaceAll("</p>br2nl"); hhtmltext = _nwln_ptrn.matcher(hhtmltext).replaceAll("br2nl"); Document soup = Jsoup.parse(hhtmltext); String plaintext = soup.text(); plaintext = _tmp_nwln_ptrn.matcher(plaintext).replaceAll("\n"); plaintext = _emptln_ptrn.matcher(plaintext.trim()).replaceAll(""); return plaintext; } catch (Throwable t) { for (int i = 1; t != null && i < 10; i++) { LOG.log(Level.SEVERE, String.format("Failed to get plaintext from while '%s' (%d %s:%s).", StringUtils.abbreviate(htmltext, 100), i, t.getClass().getName(), t.getMessage()), t); t = t.getCause(); } return "Failed to get plaintext content \n" + htmltext; } }  @Override String getPlaintext(final String htmltext);  }
@Test public void test() throws IOException { Document doc = Jsoup.connect("http: System.out.println(doc.outputSettings().charset()); String html = doc.toString(); System.out.println(html); HtmlTextExtractor extr = new JSoupTextExtractor(); String plain = extr.getPlaintext(html); System.out.println(plain); System.out.println(plain.length()); System.out.println(doc.text()); }