Fast, jQuery-style library for parsing and manipulating HTML and XML documents on the server or in the browser.
jhy/jsoup
A Java library for parsing, scraping, editing and sanitizing real-world HTML using DOM methods, CSS selectors and XPath.
- Stars
- 11,411
- Forks
- 2,319
- Open issues
- 6
- Last commit
- 3 days ago
What is it?
jsoup is a Java library for working with HTML and XML found on the web. It fetches pages from a URL, parses them from a file or string, and builds a DOM tree that follows the WHATWG HTML5 specification, so the resulting structure matches what modern browsers produce. Invalid or messy markup, often called tag soup, is still parsed into a sensible tree.
Once a document is parsed, you can locate data with DOM traversal, CSS selectors or XPath, and then read or change elements, attributes and text. The library can also output tidy HTML. For user-submitted content, it provides a safelist-based cleaner that strips disallowed tags and attributes to help prevent XSS attacks.
jsoup is distributed as a jar and through Maven and Gradle, and it is MIT licensed. The project notes that Android users should enable core library desugaring to use Java 8+ features.
Key features
- 01Parses HTML and XML from URLs, files or strings into a browser-compatible DOM.
- 02Selects elements with CSS selectors, DOM traversal or XPath.
- 03Modifies elements, attributes and text, and outputs tidy HTML.
- 04Cleans untrusted HTML against a safelist to reduce XSS risk.
- 05Handles malformed, real-world markup without failing.
Use cases
- Scraping data from web pages in a Java backend or batch job.
- Sanitizing user-submitted rich text before storing or rendering it.
- Editing or rewriting HTML templates and generated content programmatically.
- Extracting links, headlines or metadata from HTML documents in tests or tooling.
Quick start
- 1
Add the jsoup dependency to your Maven build
<dependency> <!-- jsoup HTML parser library @ https://jsoup.org/ --> <groupId>org.jsoup</groupId> <artifactId>jsoup</artifactId> <version>1.23.2</version> </dependency> - 2
Or add the jsoup dependency to your Gradle build
implementation 'org.jsoup:jsoup:1.23.1' - 3
Read the cookbook introduction and start parsing documents
Things to know
- Java library only, so it requires a JVM and Java developers.
Topics
FAQ
- What is jsoup?
- A Java library for parsing, scraping, editing and sanitizing real-world HTML using DOM methods, CSS selectors and XPath. jsoup is a Java library for working with HTML and XML found on the web. It fetches pages from a URL, parses them from a file or string, and builds a DOM tree that follows the WHATWG HTML5 specification, so the resulting structure matches what modern browsers produce. Invalid or messy markup, often called tag soup, is still parsed into a sensible tree.
- Is jsoup free to use? What license does it have?
- jsoup is open source under the MIT license. Check the license terms before using it in commercial products.
- Is jsoup still maintained?
- Actively maintained. The last commit to jsoup was on Nov 4, 2026.
- What can I use jsoup for?
- Scraping data from web pages in a Java backend or batch job. Sanitizing user-submitted rich text before storing or rendering it. Editing or rewriting HTML templates and generated content programmatically. Extracting links, headlines or metadata from HTML documents in tests or tooling.
- How do I install jsoup?
- Add the jsoup dependency to your Maven build: <dependency> <!-- jsoup HTML parser library @ https://jsoup.org/ --> <groupId>org.jsoup</groupId> <artifactId>jsoup</artifactId> <version>1.23.2</version> </dependency> Or add the jsoup dependency to your Gradle build: implementation 'org.jsoup:jsoup:1.23.1' Read the cookbook introduction and start parsing documents
- Where can I get jsoup?
- The source code and installation instructions are on GitHub: https://github.com/jhy/jsoup
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A lightweight pure-Go package that parses, queries, modifies and writes XML as an element tree, with XPath-like path queries.
A pure-JavaScript implementation of WHATWG DOM and HTML standards for running a headless DOM environment in Node.js.
HTML-to-React parser that converts HTML strings into React elements on both Node.js and the browser.
A compiler that turns declarative web components into efficient JavaScript that surgically updates the DOM.
A fast, roughly 4kB React-compatible UI library with the same modern component API, built on a Virtual DOM.