talira

Java library for parsing, scraping, cleaning and editing real-world HTML and XML

open sourceMITfree

jsoup is a Java library for working with real-world HTML and XML. It implements the WHATWG HTML5 specification and parses HTML to the same DOM as modern browsers, from a URL, a file or a string, even when the markup is invalid tag soup. It finds and extracts data with DOM traversal, CSS selectors and XPath, changes elements, attributes and text, cleans user-submitted HTML against a safelist to prevent XSS, and writes tidy HTML.

Problems it solves

  • scrape data from web pages in Java
  • parse messy, invalid HTML into a DOM in a JVM app
  • sanitize user-submitted HTML in Java to prevent XSS

Features

  • Parses HTML to the same DOM as browsers, following the WHATWG HTML5 spec
  • Fetches and parses pages from a URL, a file or a string
  • CSS selectors and XPath for finding elements
  • Edits elements, attributes and text
  • Cleans user-submitted HTML against a safelist to prevent XSS
  • Outputs tidy HTML

Limitations

  • On Android, needs core library desugaring with the NIO specification1