• March 3, 2015
  • Jsoup
  • Comments Off on Jsoup get metadata from HTML example

Jsoup get metadata from HTML example

Let us discuss how to get metadata from HTML using Jsoup API with the help of below example.

Follow the below steps:

1. Use connect(String url) method of Jsoup class which returns the connection of specified URL.
2. Use get() method of Connection class which returns Document object.
3. Get metadata (description and keywords) from document object.
4. Print metadata.



import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
 * This class is used get meta data from HTML using Jsoup.
 * @author javawithease
public class JsoupGetMetaData {
  public static void main(String args[]){
    Document document;
    try {
    	//Get Document object after parsing the html from given url.
	document = Jsoup.connect(
	//Get description from document object.
	String description = 
	//Print description.
	System.out.println("Meta Description: " + description);
	//Get keywords from document object.
	String keywords = 
	//Print keywords.
	System.out.println("Meta Keyword : " + keywords);
    } catch (IOException e) {


Meta Description: 
Jsoup get images from HTML example. Jsoup stands for Java HTML parser. 
It is an open source java library which provides API for extracting 
and manipulating data
Meta Keyword : 
jsoup, tutorial, beginners, professionals, images, 
introduction, example, java, html, parser

Download this example.
Next Topic: Jsoup get form parameters example.
Previous Topic: Jsoup get images from HTML example.

Related Topics:

How to build java project using ant in eclipse?
JAXB marshalling – convert java object to xml example.
How to create pdf file in java using iText jar?
Generics class example.
OGNL in struts 2.
Hibernate One-to-One Mapping using xml.
Send inline image in email using JavaMail API.
Quartz 2 JobListener example.


Comments are closed.