【发布时间】:2017-01-07 14:31:45
【问题描述】:
我有一个代码:
<div class="activityBody postBody thing">
<p>
<a href="/forum/conversation/post/3904-22" rel="post" data-id="3904-22" class="mqPostRef">(22)</a>
where?
</p>
</div>
我正在使用这段代码来提取文本:
html_nodes(messageNode, xpath=".//p") %>% html_text() %>% paste0(collapse="\n")
得到结果:
"(22) where?"
但我只需要“p”文本,不包括子节点中可能位于“p”内部的文本。我必须得到这个文本:
"where"
在我获取文本时有什么方法可以排除子节点吗?
Mac OS 10.11.6 (15G31)、RSrudio 版本 0.99.903、R 版本 3.3.1 (2016-06-21)
【问题讨论】:
标签: r web-scraping html-parsing rvest xml2