R 使用TM软件包阅读pdf
我正在尝试使用TM软件包读取pdf文件。我已经成功地完成了大部分尝试,但只有一次。我有几个文件夹,每个文件夹有数百个文档。除了一本外,我读了所有的书。问题是,特定文件夹中的PDF在第一页底部有一系列图像,阻止我阅读它们。我得到以下错误:R 使用TM软件包阅读pdf,r,tm,R,Tm,我正在尝试使用TM软件包读取pdf文件。我已经成功地完成了大部分尝试,但只有一次。我有几个文件夹,每个文件夹有数百个文档。除了一本外,我读了所有的书。问题是,特定文件夹中的PDF在第一页底部有一系列图像,阻止我阅读它们。我得到以下错误: Error in strptime(d, fmt) : input string is too long 如果我删除第一页,我会设法阅读它们。我可以在不损失太多相关信息的情况下完成这项工作,但工作量太大了 我尝试使用xpdf和ghoststring,但两者都给
Error in strptime(d, fmt) : input string is too long
如果我删除第一页,我会设法阅读它们。我可以在不损失太多相关信息的情况下完成这项工作,但工作量太大了
我尝试使用xpdf和ghoststring,但两者都给出了相同的错误
我的代码如下:
library(rvest)
library(tm)
url<-paste0("http://www.tjrj.jus.br/search?q=acidente+de+transito+crianca+atropelamento&btnG=Pesquisar&processType=cnj&site=juris&client=juris&output=xml_no_dtd&proxystylesheet=juris&entqrm=0&oe=UTF-8&ie=UTF-8&ud=1&filter=0&getfields=*&partialfields=(ctd:1)&exclude_apps=1&ulang=en&lr=lang_pt&sort=date:D:S:d1&as_q=+&access=p&entqr=3&start=",seq(0,462,10))
css<-sprintf(".margin-top-10:nth-child(%.d) .outros .featured",1:10)
for (j in 1:1){ # There 47 pages, but I only put one here
for (i in 1:10){ # there are 10 files per page.
a<-html_node(css=css[i]) %>%
html_attr("href")
download.file(a,paste0("doc",j,i,".pdf"))
}
}
files <- list.files(pattern = "pdf$")
Rpdf <- readPDF(control = list(text = "-layout"))
docs <- Corpus(URISource(files,encoding="UTF-8"),readerControl = list(reader = Rpdf,language="portuguese"))
库(rvest)
图书馆(tm)
url延迟回答:
但我最近发现,在当前的tm(0.7-4)版本中,readPDF默认使用pdftools来读取PDF
library(tm)
directory <- getwd() # change this to directory where pdf-files are located
# read the pdfs with readPDF, default engine used is pdftools see ?readPDF for more info
my_corpus <- VCorpus(DirSource(directory, pattern = ".pdf"),
readerControl = list(reader = readPDF))
library(tm)
目录延迟回答:
但我最近发现,在当前的tm(0.7-4)版本中,readPDF默认使用pdftools来读取PDF
library(tm)
directory <- getwd() # change this to directory where pdf-files are located
# read the pdfs with readPDF, default engine used is pdftools see ?readPDF for more info
my_corpus <- VCorpus(DirSource(directory, pattern = ".pdf"),
readerControl = list(reader = readPDF))
library(tm)
目录你能提供download.file
语句来获取PDF文件以使其可复制吗?当然。我编辑添加了下载文件的过程。非常感谢。好的,arquivos
,该对象来自哪里?试试pdftools
库,看看pdf\u text(filename)
是否解决了您的问题。我能够阅读第10个pdf.Hack-R的完整文本,将“arquivos”翻译成英文“files”并跳过了该单词。你能提供download.file
语句来获取pdf以使其可复制吗?当然。我编辑添加了下载文件的过程。非常感谢。好的,arquivos
,该对象来自哪里?试试pdftools
库,看看pdf\u text(filename)
是否解决了您的问题。我能够阅读第10期pdf.Hack-R的完整文本,将“arquivos”翻译成英文“files”,并跳过了那个单词。