1

我有一些这样的 HTML

<div>
  <a>link that I do not want to get</a>
  <div>Div that I do not want to get</div>
  Text I want to get
  <br> I like brs
  <b>That text I also want, because I like bold text</b>
  <div>I do not want all divs</div>
</div>

我想使用 xpath 来提取

Text I want to get
<br> I like brs
<b>That text I also want, because I like bold text</b>

换句话说,我想要所有 DIV 孩子,但不是 a 也不是 div。我怎样才能做到这一点?

4

1 回答 1

2

你可以self::a用来检测一个元素,然后not用来排除它们,即:

/div/node()[not(self::a or self::div)]
于 2012-07-25T16:16:34.773 回答