CodesJava

Easy learning with example program codes

Jsoup HTML parsing from URL example

Let us discuss how to parse HTML from URL 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:

JsoupParseHTMLFromURL.java

import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
 
/**
 * This class is used for HTML parsing from URL using Jsoup.
 * @author codesjava
 */
public class JsoupParseHTMLFromURL {
  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 title from HTML example.
Previous Topic: Jsoup HTML parsing from file example.

 

Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status