R 中的 download.file 包括先决条件 [英] download.file in R including pre-requisites

查看:33
本文介绍了R 中的 download.file 包括先决条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 download.file 来获取一些网页,包括嵌入的图像等.我认为使用 wget 它相当于 -p -k 选项,但我不知道该怎么做...

I'm trying to use download.file to get some webpages including embedded images, etc. I think using wget it's the equivalent of the -p -k options, but I can't see how to do this...

如果我这样做:

download.file("http://guardian.co.uk","test.html")

这显然有效,但我收到此错误:

That obviously works, but I get this error:

Warning messages:
1: running command 'wget -p -k "http://guardian.co.uk" -O "test.html"' had status 1 
2: In download.file("http://guardian.co.uk", "test.html", method = "wget",  :
  download had nonzero exit status

当我跑步时:

download.file("http://guardian.co.uk","test.html", method = "wget", extra = "-p -k") #no recursion (-r), but get pre-requisites, and (-k) convert for local viewing

我已经完成了 Sys.which("wget") &路径已设置(我不会尝试访问 https,我认为这可能会导致问题).

I've done Sys.which("wget") & the path is set (and I'm not trying to access https which I think can cause issues).

完成此操作后,我实际上想将其放入一个循环中,在该循环中我下载一组 url(及其嵌入的内容)以创建单个 html 输出...

Once I've done this I actually want to put it into a loop where I download a set of urls (& their embedded content) to create a single html output...

推荐答案

简单的解决方法,直接用system调用wget即可:

Easy solution, just use system to call wget directly:

system("wget http://guardian.co.uk -p -k")

我认为问题在于传递输出文件('test.html')意味着指定了 -O 选项,因此您不能同时调用 -r -k 而直接调用 wget 意味着它单独保存文件.

I think the issue is that passing an output file ('test.html') means -O option specified, so you can't also invoke -r -k whereas calling wget directly means it saves the files separately.

这篇关于R 中的 download.file 包括先决条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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