Jsoup select div having multiple classes

怎甘沉沦 提交于 2021-02-04 14:21:11

问题


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.

When I try the same exact syntax on JSFIDDLE, it works without a hitch.

Does multi-class selection work in Jsoup?

(I'd rather find out that this is a bug in my code than find out that this is a Jsoup limitation :)

UPDATE (thanks to the answer below): Jsoup works perfectly with the aforementioned syntax.


回答1:


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

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.




回答2:


It would by helpfull for you in near future. Have fun.

Jsoup selectors, jQuery selectors



来源:https://stackoverflow.com/questions/6152671/jsoup-select-div-having-multiple-classes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!