我正在尝试使用python自动下载历史股票数据.我尝试打开的URL以CSV文件响应,但我无法使用urllib2打开.我之前在几个问题中已经尝试更改用户代理,我甚至尝试接受响应cookie,没有运气.你能帮忙吗?
注意:同样的方法适用于雅虎财经.
码:
import urllib2,cookielib
site= "http://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/getHistoricalData.jsp?symbol=JPASSOCIAT&fromDate=1-JAN-2012&toDate=1-AUG-2012&datePeriod=unselected&hiddDwnld=true"
hdr = {'User-Agent':'Mozilla/5.0'}
req = urllib2.Request(site,headers=hdr)
page = urllib2.urlopen(req)
Run Code Online (Sandbox Code Playgroud)
错误
文件"C:\ Python27\lib\urllib2.py",第527行,在http_error_default中引发HTTPError(req.get_full_url(),代码,msg,hdrs,fp)urllib2.HTTPError:HTTP错误403:禁止
谢谢你的协助