praveenrsmart
praveenrsmart

Reputation: 89

Get text from html tag using single class name, the html tag will contain multiple class

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 know only one class name)

<p class="Body1"><span class="style3"></span><span class="style1">W</span><span class="Allsmall style5">extract this text </span><span class="style5">unwanted text </span></p>

I know the class name Allsmall alone i want to extract the text "extract this text" from the html line using Jsoup in java.

Upvotes: 0

Views: 901

Answers (1)

tmarwen
tmarwen

Reputation: 16364

You can use the selector syntax to retrieve a specific element based on its CSS class attribute:

Document doc = Jsoup.parse(
  new File("input.html"), 
  "UTF-8", 
  "http://sample.com/");

Element allSmallSpan = doc.select("span.Allsmall").first(); // Retrive the first <span> element which belongs to "Allsmall" class

Upvotes: 1

Related Questions