简体   繁体   English

使用Java中的Jsoup从HTML行获取具有类名(重写)的元素

[英]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. 我有一个html行,其中标签内有标签,一个标签包含多个类。 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. 我知道类名称“ OverRiddenClass”在“ AnyClass”类之上,我想使用Java中的Jsoup从html行中提取文本“ extract this text”以及“另一个文本要提取”。

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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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