我的目标是library(tm)在相当大的 word 文档上使用该工具包。Word 文档有合理的排版,所以我们有h1主要部分,一些h2和h3副标题。我想对每个部分进行比较和文本挖掘(每个部分下面的文本h1- 副标题并不重要 - 因此可以包含或排除它们。)
我的策略是将 worddocument 导出为 html,然后使用 pacakgervest提取段落。
library(rvest)
# the file has latin-1 chars
#Sys.setlocale(category="LC_ALL", locale="da_DK.UTF-8")
# small example html file
file <- rvest::html("https://83ae1009d5b31624828197160f04b932625a6af5.googledrive.com/host/0B9YtZi1ZH4VlaVVCTGlwV3ZqcWM/tidy.html", encoding = 'utf-8')
nodes <- file %>%
rvest::html_nodes("h1>p") %>%
rvest::html_text()
我可以提取所有的<p>,html_nodes("p")但这只是一大汤。我需要分别分析每个h1。
最好的可能是一个列表,p每个h1标题都有一个标签向量。也许是一个类似的循环for (i in 1:length(html_nodes(fil, "h1"))) (html_children(html_nodes(fil, "h1")[i]))(不起作用)。
如果有办法从内部整理单词 htmlrvest