1

我最近在实习期间开始了抓取(和一般编程),我遇到了 PDF 抓取。每次我尝试用 R 阅读扫描的 pdf 时,我都无法让它工作。我尝试使用该file.choose()功能无济于事。我是否需要更改我的目录,或者如何将 pdf 从我的文件中获取到 R 中?代码看起来像这样:

    > library(pdftools)
    > text=pdf_text("C:/Users/myname/Documents/renewalscan.pdf")
    > text
    [1] ""

此外,使用 pdftables 将我带到这里:

    > library(pdftables)
    > convert_pdf("C:/Users/myname/Documents/renewalscan.pdf","my.csv")
    Error in get_content(input_file, format, api_key) : 
    Bad Request (HTTP 400).
4

3 回答 3

4

您应该使用包pdftoolspdftables.

如果您尝试阅读 pdf 中的文本,请使用pdf_text()函数。里面是pdf的路径(在您的计算机或网络中)。例如

tt = pdf_text("C:/Users/Smith/Documents/my_file.pdf")

如果您更具体并给我们提供可重复的示例,那就太好了。

于 2018-06-07T20:52:23.073 回答
0

要使用 PDFTables R 包,您需要运行以下命令:

convert_pdf('test/index.pdf', output_file = NULL, format = "xlsx-single", message = TRUE, api_key = "insert_API_key")
于 2019-03-29T07:33:37.027 回答
0

如果您正在寻找表格数据,您可以尝试tabulizer. 这是完整的代码教程:https ://www.business-science.io/code-tools/2019/09/23/tabulizer-pdf-scraping.html

基本上,您可以使用本教程中的代码:

library(tabulizer)
extract_tables(
    file   = "2019-09-23-tabulizer/endangered_species.pdf", 
    method = "decide", 
    output = "data.frame")
于 2019-09-24T15:51:43.407 回答