试图弄清楚XPATH
匹配除 header
之外的所有元素或在 header
内.假设可以通过三个条件检测到 header :
header
例如。 <header><div.....></header>
id
其中包含字符串“header”class
其中包含字符串“header”我的 xpath:
//*[not(ancestor::header)] and //*[not(ancestor::*[contains(@id,"header")])] and //*[not(ancestor::*[contains(@class,"header")])]
是不正确的。
编辑:
这应该匹配
header
内的所有链接://*[ancestor::*[contains(@id,"header") or contains(@class,"header") or header]]
现在我想获取除这些之外的所有元素。
你知道如何让它工作吗?
最佳答案
原始 XPath 中的每个表达式都被单独评估,测试 XML 文档中是否存在满足这些条件的元素,并返回 boolean()
.
现在您已经组合了谓词以选择您不想要的特定元素,您只需要否定测试:
//*[not(ancestor-or-self::header) and
not(ancestor::*[contains(@id,"header") or contains(@class,"header")])
]
关于html - XPath - 除标题中的元素外的所有元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49220574/