简单地说:如果
x <- read.csv(url)存在,则R将返回该URL的内容.如果想尝试,一个很好的例子可能是" ichart.finance.yahoo/table.csv?s=IBM&a = 00& b = 1& c = 2008& d = 03& e = 4&f = 2014& g = d& ignore = .csv ".如果将该特定的URL分配给url并按上述方式运行,它将从Yahoo网站上将包含过去5年IBM股票数据的data.frame加载到x中.
exists, then R will return the contents of that url. A good example, if you want to try it, might be "ichart.finance.yahoo/table.csv?s=IBM&a=00&b=1&c=2008&d=03&e=4&f=2014&g=d&ignore=.csv" . That particular url, if assigned to url and run as above, will load up a data.frame into x from the Yahoo website containing the past 5 years of IBM stock data.
但是,如何事先告诉您是否有给定的网址会让您得到404错误?
But how to tell, beforehand, if any given url will get you 404'd ?
类似:
is.404.or.not(url)或者也许
status(connect.to(url))谢谢!
推荐答案您可以使用RCurl软件包:
R> library(RCurl) Loading required package: bitops R> url.exists("google") [1] TRUE R> url.exists("csgillespie") [1] FALSE或者,您可以使用httr软件包
Alternatively, you could use the httr package
R> library(httr) R> http_status(GET("google")) $category [1] "success" $message [1] "success: (200) OK" R> http_status(GET("csgillespie")) $category [1] "server error" $message [1] "server error: (503) Service Unavailable"更多推荐
如何确定url对象是否返回"404 Not Found"?
发布评论