CodesJava

Easy learning with example program codes

Jsoup get title from HTML example


Let us discuss how to get title 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. Use title() method of Document class to get the title.
4. Print the title.

Example:

JsoupGetTitle.java

import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
 
/**
 * This class is used get title from HTML using Jsoup.
 * @author codesjava
 */
public class JsoupGetTitle {
  public static void main(String args[]){
    Document document;
    try {
     	//Get Document object after parsing the html from given url.
	document = Jsoup.connect("https://codesjava.com/").get();
 
	//Get title from document object.
	String title = document.title();
 
	//Print title.
	System.out.println("Title: " + title);
    } catch (IOException e) {
	e.printStackTrace();
    }		
  }
}

Output:

Title: CodesJava | Easy learning with example program codes

Download this example.
 
Next Topic: Jsoup get links from HTML example.
Previous Topic: Jsoup HTML parsing from URL 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.

 



Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki