【发布时间】:2018-01-22 20:36:30
【问题描述】:
我想以编程方式导出this website 上的可用记录。要手动执行此操作,我将导航到该页面,单击导出,然后选择 csv。
我尝试从导出按钮复制链接,只要我有 cookie 就可以使用(我相信)。因此 wget 或 httr 请求将导致 html 站点而不是文件。
我找到了some help from an issue on the rvest github repo,但最终我无法像问题制造者那样真正弄清楚如何使用对象来保存 cookie 并在请求中使用它。
这里是我所在的位置:
library(httr)
library(rvest)
apoc <- html_session("https://aws.state.ak.us/ApocReports/Registration/CandidateRegistration/CRForms.aspx")
headers <- headers(apoc)
GET(url = "https://aws.state.ak.us/ApocReports/Registration/CandidateRegistration/CRForms.aspx?exportAll=False&exportFormat=CSV&isExport=True",
add_headers(headers)) # how can I take the output from headers in httr and use it as an argument in GET from httr?
我已经检查了 robots.txt,这是允许的。
【问题讨论】:
-
我发现的关于保存cookie的问题和答案一直使用Rselenium。要求您的程序驱动浏览器。我有兴趣了解其他途径。
-
我喜欢 Rselenium,但我一直不愿意在这种情况下使用它。