Here you can find the source of getHtmlInTag(String html, String tag)
input (html):so you can remove the input tag by using #removeTag(String)input (tag): code output:Hello world
!Hello world
Parameter | Description |
---|---|
html | searching html |
tag | tagName (learn more Tag#valueOf(String) ) |
public static Elements getHtmlInTag(String html, String tag)
//package com.java2s; //License from project: Open Source License import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; public class Main { private static Document.OutputSettings setting; /**//from w w w. j a v a2s. com * get html tag include tag too <br> * <pre>{@code * input (html): <div><code>Hello world</code>!</div> * input (tag): code * * output: <code>Hello world</code> * }</pre> * so you can remove the input tag by using {@link #removeTag(String)} * * @param html * searching html * @param tag * tagName (learn more {@link Tag#valueOf(String)}) * @return {@link Elements} (which contains of html string inside tag parameter) * @see HtmlUtil#removeTag(String) */ public static Elements getHtmlInTag(String html, String tag) { return parse(html).child(0).getElementsByTag(tag); } /** * convert html String to {@link Document} (A lot more easier to manage it) * * @param html * input html * @return Document (include html body and head Tag) * @see Document * @see Document#head() * @see Document#body() */ public static Document parse(String html) { Document document = Jsoup.parse(html); if (setting != null) return document.outputSettings(setting); return document; } }