Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an Jsoup Selector with an AND operation?

I want to find the following tag in a html.

<a href="http://www.google.com/AAA" class="link">AAA</a>

I know I can use a selector like a[href^=http://www.google.com/] or a[class=link]. But how can I combine this two conditions?

Or is there a better way to do this? Like regex? and how? Thanks!

like image 660
shiami Avatar asked Dec 16 '22 08:12

shiami


1 Answers

Just combine them in a single CSS selector.

Elements links = document.select("a[href^=http://www.google.com/][class=link]");
// ...

or

Elements links = document.select("a.link[href^=http://www.google.com/]");
// ...

Considering regex makes no sense with such a world class HTML parser.

like image 72
BalusC Avatar answered Dec 31 '22 09:12

BalusC