繁体   English   中英

查找所有出现的html元素序列

[英]find all occurrences of html elements sequences

XPath只能找到子级ev('.//div[@class="parent"]/div[@class="children"]'); ,但可悲的是没有兄弟姐妹,我需要查找所有出现的序列: <div class="1"></div><div class="2"></div><div class="3">

不是仅当其中一个存在或它们以错误的顺序出现时,您如何建议才能达到此结果?

我不确定100%是否能正确解释您的边界条件,但是如果您想准确地检测出<div>的序列,并可能使用其他表达式,可以使用以下表达式:

.//div[@class='1' and (following-sibling::div)[1][@class = '2'] and ((following-sibling::div)[2][@class = '3'])]

这将返回<div class='1'> 当然,您可以轻松地将其更改为使用class='2'class='3'返回其他事件。

如果要排除两者之间其他标签的潜在可能性,可以使用:

.//div[@class='1' and (following-sibling::*)[1][local-name()='div' and @class = '2'] and ((following-sibling::*)[2][local-name()='div' and @class = '3'])]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM