【发布时间】:2014-05-09 14:14:40
【问题描述】:
我有一个没有任何类或 id 的表格(页面上有更多表格),结构如下:
<table cellpadding="2" cellspacing="2" width="100%">
...
<tr>
<td class="cell_c">...</td>
<td class="cell_c">...</td>
<td class="cell_c">...</td>
<td class="cell">SOME_ID</td>
<td class="cell_c">...</td>
</tr>
...
</table>
我只想获取一行,其中包含 <td class="cell">SOME_ID</td> 并且 SOME_ID 是一个参数。
UPD。 目前我正在这样做:
doc = Jsoup.connect("http://www.bank.gov.ua/control/uk/curmetal/detail/currency?period=daily").get();
Elements rows = doc.select("table tr");
Pattern p = Pattern.compile("^.*(USD|EUR|RUB).*$");
for (Element trow : rows) {
Matcher m = p.matcher(trow.text());
if(m.find()){
System.out.println(m.group());
}
}
但是,如果大部分工作都是由 regexp 完成的,为什么我需要 Jsoup 呢?要下载 HTML 吗?
【问题讨论】:
-
你有什么尝试吗?
-
我只能选择所有
然后循环检查它们是否包含 SOME_ID。但问题是该页面有多个具有不同结构的表。 你可以使用 xpath 吗?但看看这个:stackoverflow.com/questions/11816878/…内容 HTML 是否是静态的,意味着总是相同的结构?@Daniel B,是的,它总是在同一页。