所以我有以下示例 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())]
如何实现我所追求的目标?
我认为以下内容符合您想要做的事情 - 它排除了包含标题的强元素及其后面的文本节点。您可以将其扩展以包含您想要排除的其他重要元素:
//div/node()[not(self::strong and contains(text(), "Title") or preceding-sibling::strong[1][contains(text(), "Title")])]
强节点被跳过:
not(self::strong and contains(text(), "Title")
以下文本被跳过:
preceding-sibling::strong[1][contains(text(), "Title")]
请注意,文本节点需要检查其最近的前同级(而不是其后同级)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)