com.datumbox.framework.core.common.text.parsers
Class HTMLParser
- java.lang.Object
-
- com.datumbox.framework.core.common.text.parsers.HTMLParser
-
public class HTMLParser extends java.lang.ObjectThe HTMLParser class is a utility class that provides a list of helpful methods which can be used to sanitize, clean up and manipulate HTML documents.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classHTMLParser.HyperlinkPartEnum with the various components of a hyperlink.
-
Constructor Summary
Constructors Constructor and Description HTMLParser()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static java.util.Map<java.lang.String,java.util.List<java.lang.String>>extractHTMLheaders(java.lang.String html)Extracts the HTML headers (h1-h6 tags) from an HTML page.static java.util.Map<HTMLParser.HyperlinkPart,java.util.List<java.lang.String>>extractHyperlinks(java.lang.String html)Extracts the hyperlinks from an html string and returns their components in a map.static java.util.Map<java.lang.String,java.lang.String>extractMetatags(java.lang.String html)Extracts the meta tags from an HTML page and returns them in a map.static java.lang.StringextractText(java.lang.String html)Extracts the text from an HTML page.static java.lang.StringextractTitle(java.lang.String html)Extracts the title of the page.static java.lang.StringremoveComments(java.lang.String html)Removes all HTML comments from string.static java.lang.StringremoveNonTextTagsAndAttributes(java.lang.String html)Removes all non-text tags (Javascript, css etc) from a string along with all the attributes from the tags.static java.lang.StringreplaceImgWithAlt(java.lang.String html)Replaces the img tags with their alt text.static java.lang.StringsafeRemoveAllTags(java.lang.String html)A safe way to remove the tags from an HTML string.static java.lang.StringunsafeRemoveAllTags(java.lang.String html)A fast way but unsafe way to remove the tags from an HTML string.
-
-
-
Method Detail
-
replaceImgWithAlt
public static java.lang.String replaceImgWithAlt(java.lang.String html)
Replaces the img tags with their alt text.- Parameters:
html-- Returns:
-
removeComments
public static java.lang.String removeComments(java.lang.String html)
Removes all HTML comments from string.- Parameters:
html-- Returns:
-
unsafeRemoveAllTags
public static java.lang.String unsafeRemoveAllTags(java.lang.String html)
A fast way but unsafe way to remove the tags from an HTML string. The method does not remove javascript, css and other non text blocks and thus it should be used with caution.- Parameters:
html-- Returns:
-
safeRemoveAllTags
public static java.lang.String safeRemoveAllTags(java.lang.String html)
A safe way to remove the tags from an HTML string. The method removes first javascript, css and other non text blocks and then removes all HTML tags.- Parameters:
html-- Returns:
-
removeNonTextTagsAndAttributes
public static java.lang.String removeNonTextTagsAndAttributes(java.lang.String html)
Removes all non-text tags (Javascript, css etc) from a string along with all the attributes from the tags.- Parameters:
html-- Returns:
-
extractText
public static java.lang.String extractText(java.lang.String html)
Extracts the text from an HTML page.- Parameters:
html-- Returns:
-
extractTitle
public static java.lang.String extractTitle(java.lang.String html)
Extracts the title of the page.- Parameters:
html-- Returns:
-
extractHyperlinks
public static java.util.Map<HTMLParser.HyperlinkPart,java.util.List<java.lang.String>> extractHyperlinks(java.lang.String html)
Extracts the hyperlinks from an html string and returns their components in a map.- Parameters:
html-- Returns:
-
extractMetatags
public static java.util.Map<java.lang.String,java.lang.String> extractMetatags(java.lang.String html)
Extracts the meta tags from an HTML page and returns them in a map.- Parameters:
html-- Returns:
-
extractHTMLheaders
public static java.util.Map<java.lang.String,java.util.List<java.lang.String>> extractHTMLheaders(java.lang.String html)
Extracts the HTML headers (h1-h6 tags) from an HTML page.- Parameters:
html-- Returns:
-
-
DataMelt 3.0 © DataMelt by jWork.ORG