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 婆婆高寿祝福语大全简短