如何在 Java 中使用 Jsoup 获取函数数据的值
How to get value of function data with Jsoup in Java
我已经使用 Jsoup 很长时间了。我需要获取 table 的值。
这就是我正在研究的 link : https://www.kayseri.bel.tr/vefat-ilanlari
这里的问题:我不能直接访问我想要的值。
正如您在下面看到的,我需要使用 item.Adsoyad 函数访问 table 值。
当我使用如下所示的 Opera 开发人员工具检查值时,我意识到我可以以某种方式访问值。现在我的问题是我该怎么做。
我只知道这部分 returns 您在日志中看到的代码。
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();
}
返回值:
E/loge:运行:{{item.AdSoyad}}
因此,如果我理解正确,您将成功找到属性 data-th
设置为 Adı Soyadı
的所有 table 字段作为元素,但您只需要获取它们的文本值。你可以这样做(Java 8 或更高):
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
我已经使用 Jsoup 很长时间了。我需要获取 table 的值。
这就是我正在研究的 link : https://www.kayseri.bel.tr/vefat-ilanlari
这里的问题:我不能直接访问我想要的值。
正如您在下面看到的,我需要使用 item.Adsoyad 函数访问 table 值。
当我使用如下所示的 Opera 开发人员工具检查值时,我意识到我可以以某种方式访问值。现在我的问题是我该怎么做。
我只知道这部分 returns 您在日志中看到的代码。
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(); }
返回值:
E/loge:运行:{{item.AdSoyad}}
因此,如果我理解正确,您将成功找到属性 data-th
设置为 Adı Soyadı
的所有 table 字段作为元素,但您只需要获取它们的文本值。你可以这样做(Java 8 或更高):
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