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 生日开业蛋糕祝福语简短