1

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

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

然后我得到...

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

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

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

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

4

1 回答 1

5

使用xmlValue. xmlGetAttr调用xmlAttrs并用于返回节点的属性。

xpathSApply(testrun,"//div[@class = 'md']/p", xmlValue)
于 2012-08-28T20:12:46.600 回答