Skip to content Skip to sidebar Skip to footer

Selecting Elements That Have Multiple Class Whilst Using Jsoup

I am parsing some tables from a website, and specifically I am trying to extract the following cells by class name: Elements e=d.select('span[class=bld lrg red]'); for (Element el

Solution 1:

You can also use regex to select the required elements in from your web page using jsoup too, there you can use and 'OR' condition to specify what you are looking for;

Example:

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

The above regex would select your span elements with classselector directly matching bld lrg red OR price (case insensitive).

Refer to here for details: http://jsoup.org/apidocs/org/jsoup/select/Selector.html

Now you may want to iterate over the elements and select which are not blank, null, both and so on.

EDIT: As per the comments, price class is not held by a span element. To get over it, you can use:

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

Post a Comment for "Selecting Elements That Have Multiple Class Whilst Using Jsoup"