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 红包祝福语简短10字
18 周六早晨祝福语简短