JSoup 排除 table 行

JSoup exclude table row

我正在使用 JSoup select 或从 table 中获取行。但是有一个问题,因为在网站上 td class 名称被弄乱了,因此我需要清理我的值并将这些元素从列表中排除。如果说我的 activity 元素包含单词 'dancing',我将如何 select 从 table 中删除整行?

    String url = "https://golf.procon.org/met-values-for-800-activities/";
    Document doc = Jsoup.connect(url).get();
    Element table = doc.select("table").get(1);

    Iterator<Element> activity = table.select("td[class=xl75]").iterator();
    Iterator<Element> specification = table.select("td[class=xl72]").iterator();
    Iterator<Element> metAmount = table.select("td[class=xl73], td[class=xl74]").iterator();

元素看起来像这样:

<td class="xl73" style="border-width: medium 0.5pt 0.5pt; border-style: none solid solid; border-color: windowtext; width: 91pt; height: 11.25pt; background-color: transparent;" width="121" height="15">dancing</td>

而且我需要排除这样的元素,可能还有这一列之后的所有列,直到行尾。 非常感谢您的帮助。

要排除具有给定文本的元素,您应该使用 notcontains pseudo selectors:

table.select("td[class=xl75]:not(:contains(dancing))")