jsoup is a Java library that simplifies working with real-world HTML and XML. It offers an easy-to-use API for URL fetching, data parsing, extraction, and manipulation using DOM API methods, CSS, and xpath selectors.
jsoup implements the WHATWG HTML5 specification, and parses HTML to the same DOM as modern browsers.
Scrape and parse HTML from a URL, file, or string.
Find and extract data using DOM traversal or CSS selectors.
Manipulate HTML elements, attributes, and text.
Clean user-submitted content against a safelist to prevent XSS attacks.
Output tidy HTML.
jsoup is designed to deal with all varieties of HTML found in the wild; from pristine and validating, to invalid tag-soup; jsoup will create a sensible parse tree.
https://jsoup.org/