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.
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
}