tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Jsoup > Selection Example3

Selection Example3 

Jsoup is an open source java library for parsing and manipulating HTML with ease. Get the latest binaries from http://jsoup.org/. This requires the library jsoup-1.6.1.jar to be in classpath. The following example shows div selection.

File Name  :  
/JSOUP001/config/html/Simple.html 

File Name  :  
com/bethecoder/tutorials/jsoup/tests/SelectTest3.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.jsoup.tests;

import java.io.IOException;
import java.io.InputStream;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class SelectTest3 {

  /**
   @param args
   @throws IOException 
   */
  public static void main(String[] argsthrows IOException {
    InputStream ins = SelectTest3.class.
        getClassLoader().getResourceAsStream("Simple.html");
    
    Document doc = Jsoup.parse(ins, "UTF-8""btc.com");
    System.out.println(doc.select("div[id$=header]"))//div id ending with header
    System.out.println(doc.select("div[id^=footer]"))//div id starting with header
    System.out.println(doc.select("div[id]"));       //divs having id as attribute
  }

}
   

It gives the following output,
File Name  :  OUTPUT



 
  


  
bl  br