chrome调试xpath

  1. 举例
$x("/html/head/script[5]/text()")[0]
  1. text()和nodeValue 使用区别
<div id="footer">
		<!--done-->
Copyright © 2021 公众号python学习开发
<br><span id="poweredby">Powered by .NET 5.0 on Kubernetes</span>
</div>


$x("//div[@id='footer']/text()")                  // (3) [text, text, text]

$x("//div[@id='footer']/text()")[1].nodeValue    // Copyright © 2021 公众号python学习开发

  1. 【深入】nodeType、nodeName和nodeValue
<script>
window.onload = function(){
    var element = document.getElementById("span");
    var text = element.firstChild;
    var property=document.getElementById("span").getAttributeNode("id");
}
</script>
<body>
  <div>
     <span id="span">文本节点</span>
  </div>
</body> 


# nodeName
alert("这是元素节点的返回值:"+ element.nodeName);//返回的标签名SPAN,注意是大写的
alert("这是文本节点的返回值:"+ text.nodeName);//返回的#text
alert("这是属性节点的返回值:"+ property.nodeName);//返回的是属性名,这里是id


# nodeValue
alert("这是元素节点的返回值:"+ element.nodeValue);//本身就没有意义,这里是试验下的,返回的是null
alert("这是文本节点的返回值:"+ text.nodeValue);//返回的是文本值  文本节点
alert("这是属性节点的返回值:"+ property.nodeValue);//返回的是属性值,这里是id的属性值span


# nodeType
alert("这是元素节点的返回值:"+ element.nodeType);//元素节点返回1
alert("这是文本节点的返回值:"+ text.nodeType);//文本节点返回3
alert("这是属性节点的返回值:"+ property.nodeType);//属性节点返回2
原文地址:https://www.cnblogs.com/amize/p/14815256.html