Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jsoup - getting class element with whitespace in name

Tags:

java

jsoup

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?

like image 987
kincaid Avatar asked Jan 28 '13 18:01

kincaid


People also ask

How to get all HTML elements by CSS class name using jsoup?

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.

How to join two classes in jsoup CSS?

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.

How do I get all the class names of an element?

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

How to use jsoup Java library in Maven build project?

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.


1 Answers

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");
like image 112
kincaid Avatar answered Oct 20 '22 17:10

kincaid