java - 使用 Jsoup 库从 android 中的网站获取 html 表的数据,
问题描述
我正在开发一个应用程序,我正在解析一个或两个网站的一些数据。幸运的是,我为我的一些目标数据做到了,但没有。现在我正在使用 Jsoup 解析来自网站的数据,我使用相同的 jsoup 格式来获取第 2 阶段的数据,就像我为我的应用程序的第 1 阶段所做的那样,但这次没有获取显示为空白的 arraylist。我检查了两个 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();
其他示例:
推荐阅读
- python-3.x - 在python3中多处理几个10K行文件的最快方法
- javascript - redux-saga-test-plan expectSaga- 使用状态分支测试 reducer
- php - 数组试图获得第一,我和一个高于/低于优化
- docker - tf.gfile.GFile 导致 docker 容器内的内存泄漏
- linux - FTDI FT232R 强制刷新 FIFO
- java - Java - Selenium - 使用 Assert 时的行为不一致
- angular - angular 7 rxjs 嵌套接口如何只取嵌套数组?
- python - 尝试使用 Python 连接到 API 时未经授权
- swift - 创建对象时“传递给不带参数的调用的参数”
- javascript - 使用外部 XML 文件在 JavaScript 中解析 xml