我正在尝试从以下html片段的“ display-ratings”跨度类中检索数字“ 1”:
<article class="surveys-verbatim__item ">
<h3 id="engine_major">
<a class="surveys-verbatim__item-title surveys-verbatim__item-title--font-large crux-body-copy crux-body-copy--bold" data-cr-collapse data-target=".surveys-verbatim__item" href="javascript:void(0);">
Engine Major
<span class="crux-icons crux-icons-caret-up-small surveys-verbatim__item__arrow"></span>
</a>
</h3>
<div class="surveys-verbatim__item-body">
<div class="row">
<div class="col-sm-6 col-xs-12">
<p class="crux-body-copy crux-body-copy--small surveys-verbatim__item-description">Engine rebuild or replacement, cylinder head, head gasket, turbo or supercharger, timing chain or timing belt.</p>
</div>
<div class="col-md-offset-2 col-md-4 col-sm-offset-1 col-sm-5 col-xs-12">
<div class="surveys-verbatim__item-ratings">
<div class="brick-chart-chart-container">
<div class="brick-chart-chart-wrapper-container clearfix">
<div class="brick-chart-chart-wrapper poor">
<div class="brick-chart-brick"></div>
<div class="brick-chart-brick active" style="width: 20%"></div>
</div>
<div class="score-range ">
<span><span class="display-ratings">1</span> / 5</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</article>
我正在Java中使用Jsoup,并具有以下代码:
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class Main {
public static void main(String[] args) throws Exception {
final Document document = Jsoup.connect("https://www.consumerreports.org/cars/audi/a6/2006/reliability?pagestop").get();
for (Element element : document.select("article.surveys-verbatim__item")) {
String rating = element.select("span.display-ratings").text();
System.out.println(rating);
}
}
}
此输出空白字符串。谁能告诉我他们是否知道如何提取跨度类“ display-ratings”中列出的值?
谢谢!