简体   繁体   中英

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.

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM