Jsoup :has() selector not working as expected

Viewed 1459

I am trying to parse a HTML table containing multiple cells with the following structure:

<td id="topic1234">
    <a name='1234'></a>
    <b><a href='/url'>Title</a><b>
    <span class='s'>Details</span>
</td>
<td id="topic2345">
    <a name='2345'></a>
    <b><a href='/url'>Title</a><b>
    <span class='s'>Details</span>
</td>
...

The 'id' attribute, 'a' element with a 'href' attribute, and 'span' element are the important details, and the two elements are directly nested. I tried using

select("[id^=topic]"
          + ":has(> b > a[href])"
          + ":has(> span.s)")

but the resulting list is empty. It works when I change it to:

select("td[id^=topic]"
          + ":has(td > b > a[href])"
          + ":has(td > span.s)")

but I don't want the selector to depend on the fact that the root element is a 'td', and judging by the documentation, the former should also work. The following didn't work either:

select("[id^=topic]"
          + ":has(:root > b > a[href])"
          + ":has(:root > span.s)")

Am I doing something wrong here? Using Jsoup 1.8.3 by the way.

2 Answers
Related