Jsoup how to select a tag with multiple attributes
I have a table tag
<table width="100%" align="center"/> And while Jsoup provides
Document document =Jsoup.parse(htmlString); document.select("table[width=100%],table[align=center]"); And this is OR, if someone matches, then the elements are filled. To select a table with width = 100% and align = center, I did the following
Elements element =document.select("table[align=center]"); element =element.select("table[width=100%]"); So, I ask, what is the same as this combination OR
document.select("table[width=100%],table[align=center]"); is there any selector of the AND combination, i.e. table width = 100% and align = center. thanks in advance
You can achieve AND with one query by adding more terms to the selector. In this case:
Elements tables = document.select("table[width=100%][align=center]"); work.
You can add additional terms to make them accurate as required, for example. table[width=100%][align=center]:contains(text)
Currently (Jsoup 1.7.1) there is no AND for the selector. But you can do this with two select() (as in example # 2):
Elements tables = document.select("table[width=100%]").select("table[align=center]"); You can also send a feature request: https://github.com/jhy/jsoup/issues