提问人:Sanku 提问时间:6/14/2016 更新时间:6/14/2016 访问量:886
Python:-关于从 url 下载文件的问题
Python:-Issue regarding downloading the file from the url
问:
我无法从网站下载文件 www.nse.com...当我尝试运行代码时,它向我显示以下消息
错误:-访问被拒绝
访问被拒绝
You don't have permission to access "http://www.nseindia.com/content/historical/EQUITIES/2016/JUN/cm13JUN2016bhav.csv.zip" on this server.<P>
Reference #18.4ef0ef75.1465880369.ab8f79e
</BODY>
</HTML>
未下载
我的代码是这样的:
法典
import urllib2
urlOfFileName="http://www.nseindia.com/content/historical/EQUITIES/2016/JUN/cm13JUN2016bhav.csv.zip"
localZipFilePath="C:\Users\sai\Desktop\cm13JUN2016bhav.csv.zip"
hdr ={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36'}
webRequest=urllib2.Request(urlOfFileName,headers=hdr)
try:
page=urllib2.urlopen(webRequest)
content=page.read()
output=open(localZipFilePath,"wb")
output.write(bytearray(content))
output.close()
except urllib2.HTTPError,e:
print e.fp.read()
print "Not Downloaded"
我也使用过User_Agent标头。我无法理解这个问题。请帮帮我解决这个问题。
答: 暂无答案
评论