jsoup query multiple selector

Nguyen Tuan Trung picture Nguyen Tuan Trung · Oct 18, 2012 · Viewed 11.7k times · Source

I have the following html:

<div>
    <h1>
        <a>1</a>
    </h1>
    <h2>
        <a>2<a>
    </h2>
    <h3>
        <a>3</a>
    </h3>
</div>

Is there a better way to select all anchors than div > h1 > a, div > h2 > a, div > h3 > a. I'm looking for something like div > (h1,h2,h3) > a

Thanks, Trung

Answer

Alex Ackerman picture Alex Ackerman · Jan 5, 2013

It's possible to achieve this:

div.select("h1,h2,h3").select("a");

alternatively, if you just need the anchors inside of the div:

div.select("a");