【发布时间】:2013-08-31 04:00:59
【问题描述】:
所以我有以下示例 html 来解析。
<div>
<strong>Title:</strong>
Sub Editor at NEWS ABC
<strong>Name:</strong>
John
<strong>Where:</strong>
Everywhere
<strong>When:</strong>
Anytime
<strong>Everything can go down there..</strong>
Lorem Ipsum blah blah blah....
</div>
我想提取整个 div,但我不希望 Title 和 Where 和 When 带有以下值。
到目前为止,我已经测试了以下 XPath。
a) 没有跟随兄弟(1:不工作。2:工作)
1. //div/node()[not(strong[contains(text(), "Title")])]
2. //div/node()[not(self::strong and contains(text(), "Title"))]
a) 有以下兄弟姐妹(1:不工作。2:不工作)
1. //div/node()[not(strong[contains(text(), "Title")]) and not(strong[contains(text(), "Title")]/following-sibling::text())]
2. //div/node()[not(self::strong and contains(text(), "Title") and following-sibling::text())]
如何实现我的追求?
【问题讨论】:
-
你能帮我说一下你想要提取的值是什么,什么不是......不太清楚......
-
我想删除强元素及其后面的文字,方法是说强元素是否包含一些文本(例如标题)。
-
<strong>Name:</strong> John然后也需要删除——对吧? -
可能是也可能不是。这个想法是编写一个选择器,可以删除任何提供其内容的强元素。
-
非常非常好的问题确实..+1..虽然xpath只能根据需要选择节点,但不能删除任何东西......