xpath中*、text()和node()区别
假设有这么一段html:
<div> <h1>Title</h1> <p>Subtitle</p> <imgsrc="a.jpg"> <div> <ahref="example.html">Goto</a> </div> Baretext <br> <!--thisishtmlcomment--> <p>Bottom</p> </div>
1child::*
节点的所有子元素,如//div[@class="post-content"]/*,结果:
<h1>Title</h1> <p>Subtitle</p> <imgsrc="a.jpg"> <div> <ahref="example.html">Goto</a> </div> <br> <p>Bottom</p>
可以看到,这里只选择了有标签名的节点,不在标签内的Baretext和注释都被过滤了。
2child::text()
节点的所有文本,如//div[@class="post-content"]/text(),结果:
Baretext
3child::node()
节点下的所有内容,不论是标签还是文本还是其他,//div[@class="post-content"]/node(),结果:
<h1>Title</h1> <p>Subtitle</p> <imgsrc="a.jpg"> <div> <ahref="example.html">Goto</a> </div> Baretext <br> <!--thisishtmlcomment--> <p>Bottom</p>
原样输出了其下的所有内容。
热门推荐
10 读书祝福语女生短句简短
11 感谢同事新婚祝福语简短
12 感谢教官文案祝福语简短
13 员工聚会蛋糕祝福语简短
14 元宵发客户祝福语简短
15 给团队信心祝福语简短
16 医美的祝福语大全简短
17 异国姻缘的祝福语简短
18 兄妹拍照祝福语简短的话