XPATH 获取 text_1 和 text_2 之间的所有节点 [英] XPATH get all nodes between text_1 and text_2

查看:27
本文介绍了XPATH 获取 text_1 和 text_2 之间的所有节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的 HTML

文本1<a>link_1</a><a>link_2</a>文本 2<a>link_3</a>文本 3

我想获取text1text2 之间的所有节点.问题是没有 pspan 标签.只有纯文本的内容是 text1text2.

我怎么能用 XPATH 做到这一点?谢谢!

解决方案

这种方式怎么样:

/div/*[前兄弟:: text()[normalize-space(.) = 'text1']和跟随兄弟:: text()[normalize-space(.) = 'text2']]

I have HTML like this

<div>
text1
<a>link_1</a>
<a>link_2</a>
text2
<a>link_3</a>
text3
</div>

I want to get all the nodes between text1 and text2. The problem is there is no p or span tag. There are only plain text with content is text1 and text2.

How could I do this with XPATH? Thank you!

解决方案

How about this way :

/div/*
    [
        preceding-sibling::text()[normalize-space(.) = 'text1'] 
            and 
        following-sibling::text()[normalize-space(.) = 'text2']
    ]

这篇关于XPATH 获取 text_1 和 text_2 之间的所有节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆