如何通过R从互联网下载文件 [英] How to download file from internet via R

查看:100
本文介绍了如何通过R从互联网下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网址,我想通过 R 下载文件,我注意到 download.file 这将是有帮助的,但我的问题似乎不同:

  url<  - http://journal.gucas.ac.cn /CN/article/downloadArticleFile.do?attachType=PDF&id=11771
destfile< - myfile.pdf
download.file(url,destfile)

它不工作!我注意到,如果我的 url xxx.pdf 的形式,那么上面的代码没有问题,否则下载的文件已损坏。



有谁知道如何解决这个问题?

解决方案

设置模式可能需要将其保存为二进制数据。如果我离开这个论点,我得到一个空白的文件,但是这样对我有用:

  url<  - http ://journal.gucas.ac.cn/CN/article/downloadArticleFile.do?
attachType = PDF& id = 11771
destfile< - myfile.pdf
下载。 file(url,destfile,mode =wb)


I have an url, and I want to download the file via R, I notice that download.file would be helpful, but my problem seems different:

url <- "http://journal.gucas.ac.cn/CN/article/downloadArticleFile.do?attachType=PDF&id=11771"
destfile <- "myfile.pdf"
download.file(url, destfile)

It doesn't work! I notice that if my url is in the form of xxx.pdf, then the code above is no problem, otherwise the file that is downloaded is corrupt.

Does anyone know how to solve this problem?

解决方案

Setting the mode might be required to treat the file as binary data while saving it. If I leave that argument out, I get a blank file, but this way works for me:

url <- "http://journal.gucas.ac.cn/CN/article/downloadArticleFile.do?
attachType=PDF&id=11771"
destfile <- "myfile.pdf"
download.file(url, destfile, mode="wb")

这篇关于如何通过R从互联网下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆