R,htmlTreeParse和xpathSApply

use*_*507 1 r html-parsing

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

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

然后我得到......

<div class ="md"> <p>我被误导了.. <p> ...

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

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

但这会吐出NULL值..当我在这里做错时,谁能告诉我?

shh*_*its 5

使用xmlValue.xmlGetAttrcalls xmlAttrs和用于返回节点的属性.

xpathSApply(testrun,"//div[@class = 'md']/p", xmlValue)
Run Code Online (Sandbox Code Playgroud)