R:获取属性的值

时间:2015-07-08 08:45:51

标签: r xpath

我想检索" position"的值。属性来自html。

以下是一个示例:

<message>

<meta date="20150707" expired="false" lastmod="Jul 08, 2015 08:00:03" matched="11" position="Jul 07, 2015 19:25:05" sentdate="Jul 07, 2015 19:25:05">

    <pubdate>Tue, 07 Jul 2015 23:25:05 +0000</pubdate>
    <summary>summaryhere</summary>
    <title>titlehere</title>

</meta>
<keywords>keywordshere</keywords>
<category>News</category>
</message>

我尝试使用此代码

date <- xpathSApply(data3,"//meta[@position]",xmlValue)

其中data3是整个html源代码。

但是,它只返回以下内容

date
 [1] "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""     "" "" "" "" "" ""
[30] "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

任何想法?

谢谢!

1 个答案:

答案 0 :(得分:1)

您可以使用:

date <- xpathSApply(data3,"//meta[@position]", xmlGetAttr, 'position')