I am trying to grab the value of this class by tag "c2 l n".
<td class="c2 l n"><span class"generic">0,63</span></td>
In Jsoup i have tried this :
String value="c2 l n";
Elements Stock_Data_Change = doc.getElementsByClass(value);
But it keeps coming up empty.. it works fine with other classnames such as "ju.l", it seems to miss the whitespaces. Anyone know a solution for this?
In this post, we are going to learn how to use jsoup Java library to get all HTML elements by CSS class name. To use jsoup Java library in the Gradle build project, add the following dependency into the build.gradle file. To use jsoup Java library in the Maven build project, add the following dependency into the pom.xml file.
If the div element had a single class named “left-align”, you could have written Jsoup CSS selector like given below. If the element contains multiple classes, you can join them using separator “.” (dot) as given below. Please note that there is no space between the two classes.
Get all of the element's class names. E.g. on element <div class="header gray">, returns a set of two elements "header", "gray". Note that modifications to this set are not pushed to the backing class attribute; use the classNames (java.util.Set) method to persist them. set of classnames, empty if no class attribute
To use jsoup Java library in the Maven build project, add the following dependency into the pom.xml file. To download the jsoup-1.13.1.jar file you can visit jsoup download page at jsoup.org/download For example, we have the sample.html file as below.
As Dave Newton answered in comments above, we are talking about elements,that has multiple classes in them. To get the value of this element, this single line grabs it for me.
Element Stock_Data_Change = doc.select("td.c2.l.n");
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