【问题标题】:R, htmlTreeParse and xpathSApplyR、htmlTreeParse 和 xpathSApply
【发布时间】:2012-08-22 11:27:55
【问题描述】:

我正在尝试解析 html 网站,但不知何故我的代码不起作用。

testrun=htmlTreeParse("网站地址", useInternalNodes = T)

然后我得到...

我被误导了.. ...

我想抓住句子(我被误导了),所以我做的是

xpathSApply(testrun,""//div[@class= 'md']//p", xmlGetAttr, "href")

但这会吐出 NULL 值。谁能告诉我我什么时候做错了?

【问题讨论】:

标签: r html-parsing


【解决方案1】:

使用xmlValuexmlGetAttr调用xmlAttrs,用于返回节点的属性。

xpathSApply(testrun,"//div[@class = 'md']/p", xmlValue)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-12
    • 1970-01-01
    • 2013-03-26
    • 1970-01-01
    相关资源
    最近更新 更多