我正在尝试从 https 页面下载一个文件,该页面需要按下“我同意”按钮,然后存储 cookie。如果这个答案在某个地方很明显,我很抱歉..
当我直接在 Chrome 中打开网页并单击“我同意”时,文件开始自动下载。
我尝试复制这个例子 https://stackoverflow.com/questions/10213194/use-rcurl-to-bypass-disclaimer-page-then-do-the-web-scrapping,但我不认为恒生网站实际上存储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 cookies
POST(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 file
writeBin(content(resp, "raw"), "c:/temp/thefile.zip")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)