xPath 不检索 HTML 作为内容的一部分 [英] xPath doesn't retrieve HTML as part of the content

查看:27
本文介绍了xPath 不检索 HTML 作为内容的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 xPath 的帮助下解析网页并检索 div 元素的内容,它省略了该 div 元素中包含的 HTML.如何让它检索包含 HTML 的 div 元素的全部内容?

I parse a web page with the help of xPath and retrieving the content of the div element, it omits HTML that is contained in that div element. How to make it retrieve the whole content of the div element with HTML included?

推荐答案

使用:

someExprSelectingtheDiv/node()

这将选择在表达式的第一个定位步骤中选择的 div 的所有子节点(标记和文本).

This selects all the children nodes (markup and text) of the divs selected in the first location step of the expression.

不要使用任何选定元素的 string() 值,因为这只是此元素的串联(按文档顺序)文本后代.

Do not work with the string() value of any selected element because this is only the concatenated (in document order) text descendants of this element.

此外,节点集的字符串值是该节点集的第一个节点(按文档顺序)的字符串值.

Also, the string value of a node-set is the string value of the first node (in document order) of this node-set.

此信息应足以解释在评估有问题的 XPath 表达式时观察到的行为.

This information should be sufficient to explain the observed behavior in evaluating the problematic XPath expression.

这篇关于xPath 不检索 HTML 作为内容的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆