
jsoup
A Java library for parsing, scraping, editing, and cleaning HTML and XML.
- Stars
- 11.4k
- Forks
- 2.3k
- Licence
- MIT
- Language
- Java
- Last update
- 9 days ago
- Type
- Library
What it is
jsoup is a Java library for working with HTML and XML found on the web. It can fetch a page from a URL, read HTML from a file or string, and let you search it with CSS selectors or DOM methods. It can also change the HTML and clean untrusted user-submitted content against a safelist to help prevent XSS attacks. It parses HTML the same way modern browsers do, so messy real-world markup still produces a usable tree.
- Fetch a web page and pull out a list of headlines or links using a CSS selector
- Clean user comments against a safelist before displaying them on a site
- Modify attributes or text inside an HTML document and output tidy HTML
- Parse HTML or XML files stored locally and extract specific elements
Great for
- Java developers who need to scrape or extract data from web pages
- Backend teams that accept HTML from users and need to sanitize it
- Projects that need to edit or tidy HTML inside a Java application
- Developers who already know CSS selectors and want to use them in Java
Not ideal for
- Non-programmers looking for a ready-made tool; it is a code library with no interface of its own
- Projects written in languages other than Java, since it is a Java library
- Heavy JavaScript-rendered pages, because the README describes parsing HTML, not running scripts in a browser
How to get it
- 1
Install with a package manager
You'll need: Java (version not specified in the README) · Maven or Gradle, or a downloaded jsoup jar
Maven dependency
<dependency><groupId>org.jsoup</groupId><artifactId>jsoup</artifactId><version>1.23.2</version></dependency>Gradle dependency
implementation 'org.jsoup:jsoup:1.23.1' - 2
Run it
- Add the jsoup dependency to your Maven or Gradle build, or download the jar from jsoup.org
- Read the cookbook introduction at jsoup.org to learn how to parse a document
- Call Jsoup.connect(url).get() to fetch and parse a page
- Use doc.select() with a CSS selector to find the elements you need
- 3
Get the most out of it
- Use the safelist sanitizer from the cookbook when handling user-submitted HTML
- Use CSS selectors or xpath selectors to target specific elements
- Use the online sample at try.jsoup.org to test selectors before writing code
- Check the API documentation at jsoup.org/apidocs for the full set of methods
Downloads
Strengths
- Parses HTML the way modern browsers do, based on the WHATWG HTML5 specification
- Simple API for fetching, selecting, and changing HTML using CSS selectors or DOM methods
- Open source under the permissive MIT license
Trade-offs
- Only usable from Java (or other JVM code), so it does not fit non-Java stacks
- The README does not describe JavaScript execution, so dynamically rendered content may not be captured
- Some Android use requires enabling core library desugaring, which adds setup work
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| jsoup (this) | 11.4k | Library | intermediate | 9 days ago | Java developers who need to scrape or extract data from web pages |
| cheerio | 30.5k | Library | beginner | 4 days ago | JavaScript developers who already know jQuery-style selectors |
| bootstrap | 175k | Library | beginner | 4 days ago | Developers building responsive websites or web app interfaces quickly |
| bulma | 50k | Library | beginner | 2 months ago | Developers who want a quick, consistent styling baseline for a web page |
| layui | 30.6k | Library | beginner | 4 days ago | Developers maintaining existing sites or admin panels built on Layui |
| gentelella | 21.6k | Library | intermediate | 6 days ago | Developers who want a starting point for an internal admin panel without adopting a frontend framework |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.