gpt4 book ai didi

java - Jsoup: "Which span does this element belong to?"

转载 作者:行者123 更新时间:2023-11-30 09:48:30 26 4
gpt4 key购买 nike

假设我找到了一个元素:

Element link = div.select("a:not([class])").first();

我现在想知道这个特定 元素是否包含在 <span class="uniqspan"> 中-- 不一定是直系后代。

有没有办法在 Jsoup 中做到这一点?

更新:我刚刚找到了精彩的 Element.parent() .我要检查这是否可以作为一个开始...

最佳答案

Element link 上不可能直接做到这一点。我建议首先收集 span.uniqspan 中的所有链接,然后检查它是否 contains 链接

例如

Element link = div.select("a:not([class])").first();
Elements linksInUniqspan = document.select("span.uniqspan a:not([class])");

if (linksInUniqspan.contains(link)) {
// Link is inside span.uniqspan.
} else {
// Link is not inside span.uniqspan.
}

关于java - Jsoup: "Which span does this element belong to?",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6206487/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com