Jsoup introduction

  • Post author:
  • Post category:Jsoup
  • Post comments:1 Comment
Jsoup introduction

Jsoup introduction is designed for beginners and professionals providing basic and advanced concepts of html parsing through jsoup.

Jsoup is a java html parser. It is a java library that is used to parse HTML document. Jsoup provides api to extract and manipulate data from URL or HTML file. It uses DOM, CSS and Jquery-like methods for extracting and manipulating file.


Jsoup Example

In this chapter, you will get a lot of examples of Jsoup. Let’s see a simple example of Jsoup technology.

  1. import java.io.IOException;  
  2. import org.jsoup.Jsoup;  
  3. import org.jsoup.nodes.Document;  
  4. public class FirstJsoupExample{  
  5.     public static void main( String[] args ) throws IOException{  
  6.                 Document doc = Jsoup.connect(“http://www.Adglob.in”).get();  
  7.                 String title = doc.title();  
  8.                 System.out.println(“title is: ” + title);  
  9.     }  
  10. }  

Jsoup Examples

In this chapter, we will see a lot of jsoup examples like loading html document, printing title from url and html file, printing total internal links of an url with text, total images of an url, meta data of an url such as keywords, description etc.

Problem

Jsoup chapter is developed and tested carefully. But if you find any problem or mistake in our chapter, you can report to us. We assure, you will not find any problem in jsoup chapter.

Install

To run any jsoup example, you need to install jsoup. The current version of jsoup is 1.8.1 till 28th november 2014. There are two ways to install jsoup:

  1. By maven pom.xml
  2. By jsoup.jar file.

1) By maven pom.xml file

Currently maven is widely used in java development. So I will recommend you to use maven for developing jsoup application.

To install jsoup using maven, add given dependency in pom.xml file.

  1. <dependency>  
  2.   <groupId>org.jsoup</groupId>  
  3.   <artifactId>jsoup</artifactId>  
  4.   <version>1.8.1</version>  
  5. </dependency>  

If you are not using maven framework, you can download the jsoup.jar file.

Now you need to set classpath of jsoup.jar file. Write following command on console.

  1. set classpath=jsoup-1.8.1.jar;.;%classpath%  

Next Topic : Click Here

This Post Has One Comment

Leave a Reply