多类元素选择说明
假设有几个多类 div,如以下 HTML 所示:
<div class="class_one class_two class_three classfour classfive classsix">
<div class="class_one class_two class_three classfour classfive">
<div class="class_one class_two class_three classfour classsix">
是否有一个 Jsoup 选择表达式可以选择所有 3 个?
为了澄清,我认为“最小公分母”会选择所有 3 个,我尝试了以下操作:
div[class=class_one class_two class_three classfour]
但它选择了无!
另一方面,使用完整的多选语法是可行的,但它只能选择上述其中一个,例如:
div[class=class_one class_two class_three classfour classfive classsix]
有没有办法使用单个 Jsoup select 语句来选择所有 3 个?
Assuming several multiclass divs as demonstrated in the following HTML:
<div class="class_one class_two class_three classfour classfive classsix">
<div class="class_one class_two class_three classfour classfive">
<div class="class_one class_two class_three classfour classsix">
Is there a single Jsoup select expression that will select all 3 of them?
To clarify, thinking that the "lowest common denominator" will select all 3, I tried the following:
div[class=class_one class_two class_three classfour]
But it selected none!
On the other hand, using the full multiselect syntax works, but it can only select one of the above, e.g.:
div[class=class_one class_two class_three classfour classfive classsix]
Is there a way to select all 3 of them, using a single Jsoup select statement?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是 Jsoup 特有的,而是 CSS 特有的。
[attribute=name]
选择器执行完全匹配。甚至顺序也很重要。您想在此处使用.classname
选择器。以下内容应该有效:请注意,类名的顺序在这里并不重要。此选择器选择具有所有给定类名的所有
元素。
另请参阅:
选择器
API javadocThis is not specific to Jsoup, but to CSS. The
[attribute=name]
selector does an exact match. Even the ordering matters. You want to use the.classname
selector here instead. The following should work:Note that ordering of the classnames doesn't matter here. This selector selects all
<div>
elements which has all of the given classnames present.See also:
Selector
API javadoc