-->

Reading Wiki Table data using Java Program

Author : Piyush Gupta

Reading Wiki Table data tutorial, We will learn that how to get table data from html page. Below Java Program reading wiki table data from wiki page and printing on console.

We will read below wiki table data using java program,

For execute below program user need to download jsoup-1.6.0.jar, If you want to download click here
Here we will read only specific column data from above wiki link that column contains Episode name in Title column.

Java Program:

import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
 
public class ZoneListFromWiki {
 
    public static void main(String[] args) {
        try {
            Document doc = Jsoup.connect("http://en.wikipedia.org/wiki/List_of_Arrow_episodes").get();
            Elements trs = doc.select("table.wikitable tr");
 
            //remove header row
            trs.remove(0);
 
            for (Element tr : trs) { 
                Elements tds = tr.select("td.summary"); 
                Element td = tds.first(); 
                if(td != null) { 
                    String episode = td.text(); 
                    episode = episode.substring(1, episode.lastIndexOf('"')); 
                    System.out.println(episode); 
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Output:

Pilot
Honor Thy Father
Lone Gunmen
An Innocent Man
Damaged……………….[and so on.]
NOTE: We can use above program for read the html table data, once will get the data then we can store in excel or whatever you want.

No comments:

Post a Comment