我正在开发一个应用程序,我正在解析来自一个或两个网站的一些数据。幸运的是,我为一些目标数据做到了这一点,但没有。现在,我正在使用 Jsoup 解析来自网站的数据,我使用与应用程序第 1 阶段相同的 jsoup 格式来获取第 2 阶段的数据,但这次没有任何内容获取显示为空白的数组列表。我检查了两个 HTML 代码,发现两者有一点不同。
在我的第一阶段,我使用它的类解析了表,然后我得到了该表的相应内容。在第二阶段,表格的格式及其 tr 和 tds 不同,所以我很难弄清楚。我正在发布我想要从中获取数据的 html 代码。
<div class="view-content">
<table class="views-table cols-3">
<thead>
</thead>
<tbody>
<tr class="odd views-row-first views-row-last">
<td class="views-field views-field-counter">
1 </td>
<td class="views-field views-field-body">
<p>some text here</p>
</td>
<td class="views-field views-field-field-notif-pdf">
<a href="https://someurl.pdf" target="_blank"></a> Size :- 1.85 MB, Language:- English</td>
</tr>
</tbody>
</table>
</div>
我想要上面的表标签中的数据,但我在弄清楚如何使用 tr 和 td 中的所有类来完成它时遇到问题。任何帮助或建议将不胜感激..
谢谢!
最佳答案
您可以在 Jsoup 中使用选择器:
File input = new File("path_to_html/test.html");
Document doc = Jsoup.parse(input, StandardCharsets.UTF_8.name());
///select table body
Element tbody = doc.select("tbody").first();
其他示例:
关于java - 使用Jsoup库从android中的网站获取html表的数据,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56017795/