我有一个这样的HTML代码:
<div class="date-item">
<tr class="row" rel="id-256">...</tr>
<tr class="row" rel="id-368">...</tr>
<tr class="row" rel="id-495">...</tr>
</div>
如何使用JSOUP计算 tr class =“row”的数量?
感谢。
答案 0 :(得分:3)
String html = "<div class=\"date-item\">\n" +
" <tr class=\"row\" rel=\"id-256\">a</tr>\n" +
" <tr class=\"row\" rel=\"id-368\">a</tr>\n" +
" <tr class=\"row\" rel=\"id-495\">a</tr>\n" +
"</div>";
Document doc = Jsoup.parse(html, "", Parser.xmlParser());
Elements els = doc.select("tr.row");
System.out.println(els.size());