praveenrsmart
praveenrsmart

Reputation: 89

Get element with class name (overridden) from HTML line using Jsoup in Java

I have a html line where there are tags inside tags, a single tag my contain multiple class. I need to extract the text with single class name(i will know only one class name which is in the tag, which may be overriding another class also)

<p class="Body1"><span class="style3"></span><span class="style1">W</span><span class="AnyClass OverRiddenClass">extract this text </span><span class="OverRiddenClass">another text to extract </span></p>

I know the class name "OverRiddenClass" which is over riding "AnyClass" class i want to extract the text "extract this text" and also "another text to extract" from the html line using Jsoup in java.

Upvotes: 0

Views: 1484

Answers (1)

meistermeier
meistermeier

Reputation: 8262

Maybe I am missing the point, but in my opinion you just have to write:

Document = Jsoup.connect(yourUrl).get();
Elements elements = document.select(".OverRiddenClass");
for (Element element : elements) {
  String text = element.text();
  // further processing
}

Upvotes: 2

Related Questions