我尝试下载一个文件,为了从服务器获取它,我需要同时发送数据。在命令行上使用curl,它可以正常工作:
curl "https://www.ishares.com/us/product-screener-download.dl" --data "productView=ishares&portfolios=239561-239855"
不幸的是我不能让它与 R 一起工作。我尝试使用 download.file、download.file 与 libcurl、curl_download 和 httr。 (使用 curl 或 wget 进行 download.file 不起作用,因为我在 Windows 计算机上。)
我尝试过但对curl不起作用:
library("curl")
handle <- new_handle()
handle_setopt(handle, customrequest = "POST")
handle_setform(handle, productView="ishares",portfolios="239561-239855")
curl_download("https://www.ishares.com/us/products/etf-product-list", "./data/ishares-us-etf.xls", handle=handle)
我尝试过但对 httr 不起作用:
library(httr)
POST("https://www.ishares.com/us/products/etf-product-list", body = list(productView="ishares",portfolios="239561-239855"))
找到一些周围之后Fiddler http://www.telerik.com/fiddler我发现我需要用邮局发送数据,然后一切正常。
library("curl")
handle <- new_handle()
handle_setopt(handle, customrequest = "POST")
handle_setopt(handle, postfields='productView=ishares&portfolios=239561-239855')
curl_download("https://www.ishares.com/us/product-screener-download.dl", "./data/ishares-us-etf.xls", handle=handle)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)