Choosing Elements That Have Multiple Classes When Using JSoup

I am analyzing some tables from a website, and in particular, I am trying to extract the following cells by class name:

Elements e=d.select("span[class=bld lrg red]");

for (Element element : e) {
System.out.println(element.text());}

this code gives me some values ​​that are given as Price on the website. but in some cases I want to take the price from another class, not "span[class=bld lrg red]".

I mean, the class "bld lrg red" is empty, then I want to take the value from "span [class = price]"

How can I use "or" in this case. I mean, if the class "bld lrg red" has a value, then take this price or take the value of the class "price".

+3
source share
1 answer

regex, -, jsoup, "", , ;

:

Elements e = d.select("span[class~=(?i)(bld lrg red|price)]");

span class, bld lrg red price ( ).

. : http://jsoup.org/apidocs/org/jsoup/select/Selector.html

, , , ..

EDIT: price class span. , :

Elements e = d.select("span[class=bld lrg red],del[class=price]");
+3

All Articles