
当我直接在Chrome中打开网页并单击“我同意”时,文件开始自动下载.
http://www.icpsr.umich.edu/cgi-bin/bob/zipcart2?path=SAMHDA&study=32722&bundle=delimited&ds=1&dups=yes
我试图复制this example,但我不认为hangseng网站实际上存储了cookie /身份验证,因此我不知道该示例是否应该是我需要的全部内容.
除此之外,我认为SSL使身份验证变得复杂,因为我认为getURL()调用将需要证书规范,如cainfo = system.file(“CurlSSL”,“cacert.pem”,package =“RCurl”))
我太过RCurl的初学者了解这个网站是否相当困难,或者我是否只是遗漏了一些明显的东西.
谢谢!
解决方法 这对于httr来说更容易一些,因为它设置了所有内容,以便cookie和https无缝地工作.生成cookie的最简单方法是让网站为您执行此 *** 作,方法是手动发布“我同意”表单生成的信息.然后,您再次请求下载实际文件.
library(httr)terms <- "http://www.icpsr.umich.edu/cgi-bin/terms"download <- "http://www.icpsr.umich.edu/cgi-bin/bob/zipcart2"values <- List(agree = "yes",path = "SAMHDA",study = "32722",ds = "",bundle = "all",dups = "yes")# Accept the terms on the form,# generating the appropriate cookiesPOST(terms,body = values)GET(download,query = values)# Actually download the file (this will take a while)resp <- GET(download,query = values)# write the content of the download to a binary filewriteBin(content(resp,"raw"),"c:/temp/thefile.zip")总结
以上是内存溢出为你收集整理的如何使用R从需要cookie的SSL页面下载压缩文件全部内容,希望文章能够帮你解决如何使用R从需要cookie的SSL页面下载压缩文件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)