R:下载嵌入网页的pdf

R: download pdf embedded in a webpage

试图找到一种更简单的方法来获取此 page 中嵌入的 pdf 中的 table 甚至更好,请将此 pdf 下载到本地驱动器中:

我的代码如下,结果很乱...

PS:网页底部的按钮 none 有效,除非你使用 IE,IE 和 RSelenium ...我已经创建了一个代码来在 IE 上加载页面,可以成功单击任何按钮以加载 excel 文件(卡在弹出 window 要求我打开或保存的步骤)或打开当前 window,但同样的问题,不知道如何获取pdf。所以到处都是死胡同

提前致谢。

library(RSelenium)
checkForServer()
startServer()
remDr<-remoteDriver$new()
url<-"http://www.dmo.gov.uk/ceLogon.aspx?page=about&rptCode=D10A"
remDr$open(silent = TRUE) #opens a browser
remDr$navigate(url)
doc <- htmlParse(remDr$getPageSource()[[1]])

table <- readHTMLTable(doc, header=NA, stringsAsFactors=TRUE) 

需要 IE 才能与该页面进行有效交互的说法是不正确的。在 Mac 上使用 Firefox 或 Chrome 时,数据列上方和左侧的小打印机图标会在 moused-over 和单击时提供给 "Print this report" 并导致名为 "CrystalReportViewer1.pdf"待下载。如果然后使用 cross-platform browser-plugin application named Tabula,您可以提取 csv 格式的数据。提取数据的顶部(2016 年 4 月 1 日)如下所示:

Syndication ,Gilt Name ,Amount Sold ,Issue ,Issue ,Announcement ,Results 
Date ,"",(£ million ,Price (£) ,Yield ,Press Release ,Press Release
"","",nominal),"","","",""
23 Feb 2016 ,0 1/8% Index-linked Treasury Gilt 2065 ," 2,750.0 ", 163.73 ,-0.8905% ,Announcement ,Results
01 Dec 2015 ,0 1/8% Index-linked Treasury Gilt 2046 ," 3,250.0 ", 129.74 ,-0.7475% ,Announcement ,Results
20 Oct 2015 ,2½% Treasury Gilt 2065 ," 4,750.0 ", 98.40 , 2.5570% ,Announcement ,Results
22 Sep 2015 ,0 1/8% Index-linked Treasury Gilt 2068 ," 2,500.0 ", 166.00 ,-0.8655% ,Announcement ,Results
21 Jul 2015 ,3½% Treasury Gilt 2068 ," 4,000.0 ", 121.31 , 2.7360% ,Announcement ,Results

与其尝试从该页面提取 pdf(据我所知这不是 pdf 格式),不如使用 RSelenium 将 pdf 文件下载到本地驱动器并从那里进行处理。

这是按钮 ID:

{'id':'CrystalReportViewer1_toptoolbar_print'}

RSelenium 帮助页面中有演示。一个标题为:selDownloadZip.R。它展示了如何在 "page Element":

上执行 "click"
webElem <- remDr$findElement("id", "CrystalReportViewer1_toptoolbar_print")
webElem$clickElement()

然后在 Firefox 的 ViewSource 面板中查看 "element Inspector",我看到按钮的名称("id"、"theBttnbobjid_1459536946505_dialog_submitBtn"),因此需要进一步单击。但是,该数字会随着每次访问页面而变化,因此请使用 webElem <- remDr$findElement("link text", "Export")

 webElem <- remDr$findElement("link text", "Export")
 webElem$clickElement()

查看 webElement-class 帮助页面是个好主意。