提问人:prashant kumar singh 提问时间:5/7/2019 最后编辑:Nazim Kerimbekovprashant kumar singh 更新时间:5/7/2019 访问量:761
使用 Jsoup 库从 android 网站获取 html 表的数据,
Get data of html table from a website in android using Jsoup library,
问:
我正在开发一个应用程序,我正在解析来自一个或两个网站的一些数据。幸运的是,我为我的一些目标数据做了这件事,但没有。现在我正在使用 Jsoup 解析来自网站的数据,我使用相同的 jsoup 格式来获取第 2 阶段的数据,就像我在应用程序的第 1 阶段所做的那样,但这次没有获取任何内容,arraylist 显示为空白。我检查了两个HTML代码,两者之间都有一些不同。
在我的 phase1 中,我使用它的类解析了该表,然后我得到了该表的相应内容。在第二阶段,表格的格式及其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"></a> Size :- 1.85 MB, Language:- English</td>
</tr>
</tbody>
</table>
</div>
我想要上面表格标签内的数据,但我在弄清楚如何对 tr 和 td 中的所有类完成它时遇到了问题。任何帮助或建议将不胜感激。
谢谢!
答:
0赞
Nikita
5/7/2019
#1
您可以在 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();
其他示例:
评论