İlgili Ders : JSoup İle Web sitesinden HTML Verisi Çekme
Öncelikle bilgisayarımda index.html adında şöyle bir dosya var :
<html> <head> <title> Java4Fun - JSoup Dersleri </title> </head> <body> <table id="kisiListesi"> <tr> <td>Türker</td> <td>Sağlam</td> <td>50</td> </tr> <tr> <td>Neşe</td> <td>Yalçın</td> <td>23</td> </tr> </table> </body> </html>
JSoupDemo.java Dosyası
import java.io.File; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; public class JSoupDemo { public static void main(String[] args) { try { File file = new File("K:/index.html"); Document doc = Jsoup.parse(file, "UTF-8"); Elements table = doc.select("table[id=kisiListesi]"); //kisiListesi tablosundaki tum satir elementlerini al Elements rows = table.select("tr"); //Her bir satir icin tum kolonlari dolas for (Element row : rows) { //Bu satira ait kolon elementlerini bul Elements columns = row.select("td"); //Her kolonun icerigini yazdir for (Element column : columns) { System.out.println(column.text()); } System.out.println("\n"); } } catch (Exception e) { e.printStackTrace(); } }
}
Merhabalar
YanıtlaSilAnlatımınız için çok teşekkürler. Html deki sadece bir classtaki verileri çekerken nasıl bir yol izlemeliyiz peki ?