Cheap VPS & Xen Server

Residential Proxy Network - Hourly & Monthly Packages

Get Metadata of URL


In this example, we will print the meta keywords and description of an URL. To do so, you need to call select(), first(), get() and attr() methods of Document class.

  1. import java.io.IOException;
  2. import org.jsoup.Jsoup;
  3. import org.jsoup.nodes.Document;
  4. public class JsoupPrintMetadata {
  5.      public static void main( String[] args ) throws IOException{
  6.             Document doc = Jsoup.connect(“http://www.Kreationnext.com”).get();
  7.             String keywords = doc.select(“meta[name=keywords]”).first().attr(“content”);
  8.             System.out.println(“Meta keyword : ” + keywords);
  9.             String description = doc.select(“meta[name=description]”).get(0).attr(“content”);
  10.             System.out.println(“Meta description : ” + description);
  11. }
  12. }

Output:

Meta keyword : jsoup, tutorial, beginners, professionals, introduction, example, java, html, parser
Meta description : Jsoup tutorial for beginners and professionals provides html parsing facility 
in java with examples of printing title, links, images, form elements from url. 

Comments

comments