0

我有以下 HTML:

some text <b>some bold text</b>
<span property='some property1>
some semantic term2</span> 
<p><span id='mark1'></span>
some text <i>some italic text</i></p>
<span property='some property2'>
some semantic term</span>
<span id='mark2'></span>

我想选择所有带有“property”属性的span元素,它们位于ids为“mark1”和“mark2”的span元素之间(这些是我的技术书签,然后应该将其删除)并打开它。

我认为在 Java Jsoup 中实现它的最佳方法是使用 doc.select 函数。但是我无法创建正确的 CSS 查询(我需要类似的东西:每个 span 元素都具有这两个元素之间的属性属性)。

预期结果(删除书签后):

  some text <b>some bold text</b>
    <span property='some property1>
    some semantic term2</span> 
    <p>
    some text <i>some italic text</i></p>
    some semantic term

有任何想法吗?也许像 E ~ F 之类的东西。非常感谢!

4

1 回答 1

0

This is not possible: the Jsoup selector syntax is not expressive enough to select all tags between two arbitrarily-positioned tags.

However, you can use the NodeTraverser class with a NodeVisitor implementation that collects all elements visited between the two bookmark elements. (This should be easier than "some awful recursion" referenced in your comment.)

于 2014-06-21T19:01:00.337 回答