Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
XPathApply-如何从TreeParse获取结果_R_Xml - Fatal编程技术网

XPathApply-如何从TreeParse获取结果

XPathApply-如何从TreeParse获取结果,r,xml,R,Xml,我很难让标记通过XPathApply解析信息。网站上需要的信息是一个“输入”单元,我不知道如何检索它。例如,使用以下信息,我可以将其提取为: <div><span>3.2</span></div> <div><span>6.9</span></div> <div><span>2.5</span></div> as.numeric(unlist(xpat

我很难让标记通过XPathApply解析信息。网站上需要的信息是一个“输入”单元,我不知道如何检索它。例如,使用以下信息,我可以将其提取为:

<div><span>3.2</span></div>
<div><span>6.9</span></div>
<div><span>2.5</span></div>

as.numeric(unlist(xpathApply(*HTMLText*, '//span', xmlValue))
3.2
6.9
2.5
as.numeric(未列出(xpathApply(*HTMLText*,'//span',xmlValue))
但是,我有这样的行:

<div class="editable-cell"><input type="text" tabindex="2" value="32"></div>
<div class="editable-cell"><input type="text" tabindex="2" value="33"></div>
<div class="editable-cell"><input type="text" tabindex="2" value="20"></div>

我不知道使用哪种类型的标记来检索
value=“*”
中的值。我尝试了'//value'、'//div'等,但它对我不起作用

我为没有真正创建可复制的代码提前表示歉意,但我认为识别获取值所需的标记是很容易的。另外,是否有任何资源可以更好地识别我需要的标记


谢谢

您可以使用
XML::xmlAttrs
检索属性

library(XML)
doc <- htmlParse('<div class="editable-cell"><input type="text" tabindex="2" value="32"></div>
<div class="editable-cell"><input type="text" tabindex="2" value="33"></div>
<div class="editable-cell"><input type="text" tabindex="2" value="20"></div>')

unlist(lapply(xpathApply(doc, '//input', xmlAttrs), '[[', "value"))

#or
xpathSApply(doc, '//input', function(x) xmlAttrs(x)[["value"]])

#or as suggested by @har07
xpathSApply(doc, '//input/@value', I)
库(XML)

doc使用
xmlAttrs
?我不熟悉
r
,但是从元素
input
获取属性
value
的XPath是:
//input/@value
非常感谢您的帮助。我查阅了所有文档,在上一个示例的末尾,我找不到
I
的作用,您能解释一下吗普通?我也永远无法理解
'[['
lappy
sCheck out?I中是什么。它返回自己?“[['访问一个列表哇,听起来我需要停止依赖
dplyr
并了解更多关于基函数的信息。再次感谢您的帮助