首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从get in R网站下载zip中的csv时出错

从get in R网站下载zip中的csv时出错
EN

Stack Overflow用户
提问于 2014-09-28 16:12:13
回答 2查看 1.8K关注 0票数 0

我想使用download.file()从nse-india.com读取数据到R,如下所示。

代码语言:javascript
运行
复制
url = 'http://www.nseindia.com/content/historical/EQUITIES/2014/SEP/cm24SEP2014bhav.csv.zip'
temp = tempfile()
download.file(url, destfile = temp,method = 'wget')

它抛出以下错误:

代码语言:javascript
运行
复制
SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc
syswgetrc = C:\PROGRA~2\GnuWin32/etc/wgetrc
--2014-09-28 21:19:26--  http://www.nseindia.com/content/historical/EQUITIES/2014/SEP/cm24SEP2014bhav.csv.zip
Resolving www.nseindia.com... 202.83.22.200, 202.83.22.203
Connecting to www.nseindia.com|202.83.22.200|:80... connected.
HTTP request sent, awaiting response... 403 Forbidden
2014-09-28 21:19:26 ERROR 403: Forbidden.

Warning messages:
1: running command 'wget  "http://www.nseindia.com/content/historical/EQUITIES/2014/SEP/cm24SEP2014bhav.csv.zip" -O "C:\Users\ITITHI~1\AppData\Local\Temp\Rtmp2fjADx\file1fb02375882"' had status 1 
2: In download.file(url, destfile = temp, method = "wget") :
  download had nonzero exit status

无论如何,请让我知道来解决这个问题。

编辑:或者从R内部下载文件的任何其他方法都是很棒的。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-09-29 03:55:26

您需要设置一个类似浏览器的用户代理字符串,这样站点就会认为您是浏览器,而不是自动刮板/下载机器人:

代码语言:javascript
运行
复制
library(httr) # >=v0.5

GET("http://www.nseindia.com/content/historical/EQUITIES/2014/SEP/cm24SEP2014bhav.csv.zip",
    user_agent("Mozilla/5.0"), write_disk("cm24SEP2014bhav.csv.zip"))

## Response [http://www.nseindia.com/content/historical/EQUITIES/2014/SEP/cm24SEP2014bhav.csv.zip]
##   Date: 2014-09-28 23:53
##   Status: 200
##   Content-type: application/zip
##   Size: 58.2 kB
## <ON DISK>  cm24SEP2014bhav.csv.zip
票数 0
EN

Stack Overflow用户

发布于 2014-09-28 17:09:27

你需要许可才能访问那个网站。下面是来自httr包的消息(在doc中):

代码语言:javascript
运行
复制
url = 'http://www.nseindia.com/content/historical/EQUITIES/2014/SEP/cm24SEP2014bhav.csv.zip'
doc <- content(GET(url))


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head><title>Access Denied</title></head>
<body>
<h1>Access Denied</h1>

You don't have permission to access "http://www.nseindia.com/content/historical/EQUITIES/2014/SEP/cm24SEP2014bhav.csv.zip" on this server.<p>
Reference #18.df24317.1411924047.3b4f02a1
</p>
</body>
</html>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26086868

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档