Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jsoup query multiple selector

Tags:

jsoup

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

like image 277
Nguyen Tuan Trung Avatar asked Oct 18 '12 17:10

Nguyen Tuan Trung


2 Answers

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");
like image 183
Alex Ackerman Avatar answered Nov 19 '22 14:11

Alex Ackerman


You can select h1,h2,h3 elements using select("h1,h2,h3")

like image 43
Sai Sunder Avatar answered Nov 19 '22 16:11

Sai Sunder