在R中下载Kaggle zip文件
我试图直接从R代码中的Kaggle空间下载zip文件。不幸的是,结果不太对劲。下面是正在发生的事情: <旧金山犯罪数据集在R中下载Kaggle zip文件,r,zip,kaggle,R,Zip,Kaggle,我试图直接从R代码中的Kaggle空间下载zip文件。不幸的是,结果不太对劲。下面是正在发生的事情:
获取第一个数据集:test.csv.zip:
我使用的是R代码:download.file(url='https://www.kaggle.com/c/sf-crime/download/test.csv.zip', destfile = 'test.zip',method = 'curl')
代替原来的18.75MB文件,R只下载183字节的文件
会话输出:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0100 183 100 183 0 0 665 0 --:--:-- --:--:-- --:--:-- 667
我做错了什么
提前感谢,,
拉胡尔
仅供参考:像使用web客户端一样使用RCurl。您登录过Kaggle吗?您可能刚刚收到以下信息:
对象已移动到代码>是的,我已登录Kaggle。
library(RCurl)
#Set your browsing links
loginurl = "https://www.kaggle.com/account/login"
dataurl = "https://www.kaggle.com/c/titanic/download/train.csv"
#Set user account data and agent
pars=list(
UserName="suiwenfeng@live.cn",
Password="-----"
)
agent="Mozilla/5.0" #or whatever
#Set RCurl pars
curl = getCurlHandle()
curlSetOpt(cookiejar="cookies.txt", useragent = agent, followlocation = TRUE, curl=curl)
#Also if you do not need to read the cookies.
#curlSetOpt( cookiejar="", useragent = agent, followlocation = TRUE, curl=curl)
#Post login form
welcome=postForm(loginurl, .params = pars, curl=curl)
bdown=function(url, file, curl){
f = CFILE(file, mode="wb")
curlPerform(url = url, writedata = f@ref, noprogress=FALSE, curl = curl)
close(f)
}
ret = bdown(dataurl, "c:\\test.csv",curl)
rm(curl)
gc()