user3517658
user3517658

Reputation: 379

Ignore whole class if subclass contains unwanted value with jsoup

I do this in my Activity:

Document doc = Jsoup.connect(https://greselius.net/idesk/vplan/Anzeige/Schueler_heute/subst_001.htm).get(
                );
                Elements questions = doc.select("table.mon_list");
                Elements td = questions.select("td.list:not(.inline_header)");

The website it connects to is a substitute teacher plan. This gets me all elements that contain data of the affected school class, lesson, teacher, etc. But it gets that for all school classes and I want to get only the elements for one specific school class. Lets say I want only the ones that contain 9c, how can I ignore the other ones?

<tr class="list odd">
<td class="list" align="center">9c</td><td class="list" align="center">5</td><td class="list" align="center">LÜB</td><td class="list" align="center">Ph</td><td class="list" align="center">Ph1</td><td class="list" align="center">LÜB</td><td class="list" align="center">Raum-Vtr.</td><td class="list" align="center">&nbsp;</td>
</tr>

Upvotes: 0

Views: 165

Answers (1)

Jeffrey Bosboom
Jeffrey Bosboom

Reputation: 13653

Depending on the desired scope of the search, you want one of the :contains(), :containsOwn(), :matches() and :matchesOwn() selectors.

To select only table cells in table rows containing 9c, you'd use tr:contains(9c) td; note that while the selector is applied to tr, the child elements are also searched. If you instead used td:contains(9c), you'd only get the single cell, not its siblings in the row (though you could iterate on the returned elements' siblings, of course).

try.jsoup.org can't fetch the URL you provided due to a certificate error, so I can't give you the exact query you need, but that should get you started.

Upvotes: 1

Related Questions