如何获得HTML树的#Text节点数组
I need to use all the #text elements of an html body as an array.
The rich text can have various levels so I need to get to the lowest element.
For example for the text below I'm expecting to have an array of 8 elements.
What is the name or tag or method to get the # text node?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以通过节点递归扫描并将文本节点推入数组。
You can recursively scan through the nodes and push the text nodes into an array.
您需要指定第一个父标签并使用InnerText属性。
或者,如果您想使用jQuery,则可以这样做。
You need to specify the first parent tag and use innerText attribute.
or if you want to use jquery , you can do like this.
最简单的方法是使用XPath,以下表达式返回给您所有具有文本的节点,
如果您只想获取所有文本,请使用以下内容
The easiest way is to use Xpath, the following expression return to you all the nodes that have text
if you just want to get all the text, use the following