I have a table tag
<table width="100%" align="center"/>
And so far Jsoup provides
Document document =Jsoup.parse(htmlString);
document.select("table[width=100%],table[align=center]");
And this is OR comination i.e. if any one matches then elements are populated. In order to select table having width =100% and align =center I have done following
Elements element =document.select("table[align=center]");
element =element.select("table[width=100%]");
So what I am asking is that just like this OR combination
document.select("table[width=100%],table[align=center]");
is there any AND combination selector i.e. table having width =100% and align =center. Thanks in advance
You can achieve an AND with one query by adding more terms to the selector. In this instance:
Elements tables = document.select("table[width=100%][align=center]");
works.
You can keep adding more terms to make it as precise as required, e.g. table[width=100%][align=center]:contains(text)
At the moment (Jsoup 1.7.1) there no AND for selector available. But you can do this with two select()
's (like in your example #2):
Elements tables = document.select("table[width=100%]").select("table[align=center]");
You can also post a feature request: https://github.com/jhy/jsoup/issues
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With