如何检索HTML DOM中的所有文本,但不包括SCRIPT和STYLE标签? [英] How do I retrieve all text in an HTML DOM but exclude SCRIPT and STYLE tags?
本文介绍了如何检索HTML DOM中的所有文本,但不包括SCRIPT和STYLE标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何从DOM中快速提取文本节点:
I know how to quickly extract text nodes from a DOM:
document.evaluate('//text()', document, null, XPathResult.ANY_TYPE, null)
但是有一种简单的方法来排除文本SCRIPT,STYLE或其他不会向用户显示的标签?
But is there an easy way to exclude text from SCRIPT, STYLE, or other tags that are not shown to the user?
类似于:
'//text()[ parent.name not in ("SCRIPT", "STYLE") ]'
谢谢,
Mike
Thanks, Mike
推荐答案
//*[not(self::script or self::style)]/text()
这篇关于如何检索HTML DOM中的所有文本,但不包括SCRIPT和STYLE标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文