Jsoup Select div具有多个类 [英] Jsoup select div having multiple classes
问题描述
我试图使用 Jsoup 选择具有多个类的<div>
:
I am trying to select, using Jsoup, a <div>
that has multiple classes:
<div class="content-text right-align bold-font">...</div>
据我所知,这样做的语法应为:
The syntax for doing so, to the best of my understanding, should be:
document.select("div.content-text.right-align.bold-font");
但是,由于某种原因,这对我不起作用.
However, for some reason, this doesn't work for me.
当我在 JSFIDDLE 上尝试使用完全相同的语法时,它会顺利运行.
When I try the same exact syntax on JSFIDDLE, it works without a hitch.
在 Jsoup 中可以进行多类别选择吗?
Does multi-class selection work in Jsoup?
(我宁愿发现这是我的代码中的错误,也不愿发现这是Jsoup的局限性:)
(I'd rather find out that this is a bug in my code than find out that this is a Jsoup limitation :)
更新(由于以下答案):Jsoup可以与上述语法完美配合.
UPDATE (thanks to the answer below): Jsoup works perfectly with the aforementioned syntax.
推荐答案
使用最新的Jsoup(1.5.2)为我工作.
Works for me with latest Jsoup (1.5.2).
String html = "<div class=\"content-text right-align bold-font\">foo</div>";
Document document = Jsoup.parse(html);
Elements elements = document.select("div.content-text.right-align.bold-font");
System.out.println(elements.text()); // foo
因此,您可能正在使用过时的Jsoup版本,该版本暴露了与此相关的错误,或者实际的HTML不包含这样的<div>
.
So either you're possibly using an outdated version of Jsoup which exposes a bug related to this, or the actual HTML doesn't contain a <div>
like that.
这篇关于Jsoup Select div具有多个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!