How can I parse ul elements in a HTML document with a specific class type using Java?
I want to pars this section from HTML:
-
KİM 101 Final Mazeret Sınavı
-
Bütünleme Sınav Tarihleri
-
Bil 374 İnternet Teknolojileri Final Sınavı
-
Kim101 Final Sınavı
-
Doktora Yeterlilik Sınav Tarihleri
-
Doktora Programı Adaylarına Önemli Duyuru
-
2012-2013 Eğitim-Öğretim Yılı Güz Yarı Yılı Final Programı
-
Yüksek Lisans / Doktora Seminer I ve II Sunum Takvimi
-
Bilgisayar Mühendisliği Bölümü 2012-2013 Güz Yarı Yılı Ders Programları
Bilgisayar Mühendisliği Bölümü 2012-2013 Güz Yarı Yılı Ders Programları
-
KİM 101 Kimya Dersi II .vizesi
-
Yüksek Lisans/Doktora Seminer I ve II Ders Planı
-
BIL 495/496 Bitirme Projesi Ders Planı
-
G.Y.T.E. Lisans Üstü Öğrencilerinin Dikkatine
-
BİL 341 Programlama Dilleri bütünleme sınavı
I have following code to parse but it does not work:
try {
URL url = new URL("http://www.gyte.edu.tr/kategori/120/0/duyurular.aspx");
HTMLEditorKit kit = new HTMLEditorKit();
HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
Reader HTMLReader = new InputStreamReader(url.openConnection().getInputStream());
kit.read(HTMLReader, doc, 0);
ElementIterator it = new ElementIterator(doc);
Element elem;
while ((elem = it.next()) != null) {
AttributeSet as = elem.getAttributes();
if (as.containsAttribute("class", "news-list")) {
int c = elem.getElementCount();
System.out.println("Element count = " + c);
}
}
} catch (IOException | BadLocationException e) {
e.printStackTrace();
return e.getMessage();
}
return "Success!";