Search code examples
javaandroidjsouphtml-parsing

How to get value of function data with Jsoup in Java


I've been using Jsoup for a long time. I need to get values of a table.

That's the link i'm work on : https://www.kayseri.bel.tr/vefat-ilanlari

The problem here: I can't directly access the values I want.

As you can see at below i need to access table values with item.Adsoyad function.

values i want

When i check values with opera developer tools like below i realized i can access values somehow. Now my question is how do I do this.

values i reached

I only came until this part which returns the code you see in Log.

try { Document document = Jsoup.connect("https://www.kayseri.bel.tr/vefat-ilanlari").timeout(10000).get();

if (document != null) { Elements adiSoyadi = document.select("tbody td[data-th = Adı Soyadı]"); Log.e("loge", "run: " + adiSoyadi.text()); } } catch (IOException e) { e.printStackTrace(); }

Returning value :

E/loge: run: {{item.AdSoyad}}


Solution

  • So if I understand correctly you are succeeding in finding all the table fields that have the attribute data-th set to Adı Soyadı as Elements, but you just need to get their text values. You can do that like this (with Java 8 or higher):

    List<String> values = adiSoyadi.stream() // streaming all the elements 
    .map(e -> e.text()) // getting the text from each element
    .collect(Collectors.toList()) // collecting the Strings in a list