$ pip install yahoo-finance
$ python

然后在python控制台中,

>>> from yahoo_finance import Share
>>> yahoo = Share('YHOO')

回溯(最近一次调用最后一次):文件“”,第1行,在文件“/Users/ishandutta2007/virtualenvironment/googlfin/lib/python2.7/site-packages/yahoo_finance/init.py”,第178行,在init中self.refresh()文件“/Users/ishandutta2007/virtualenvironment/googlfin/lib/python2.7/site-packages/yahoo_finance/init.py”,第142行,刷新self.data_set = self.fetch()文件“/ Users / ishandutta2007 / virtualenvironment / googlfin / lib / python2.7 / site-packages / yahoo_finance / init.py“,第181行,在_fetch data = super(Share,self). fetch()File”/ Users / ishandutta2007 / virtualenvironment /googlfin/lib/python2.7/site-packages/yahoo_finance/init.py“,第134行,在_fetch data = self._request(query)File”/Users/ishandutta2007/virtualenvironment/googlfin/lib/python2.7/ site-packages / yahoo_finance / init.py“,第118行,在_request response = yql.YQLQuery() . execute(query)File”/Users/ishandutta2007/virtualenvironment/googlfin/lib/python2.7/site-packages/yahoo_finance /yql.py“,第61行,执行'env':DATATABLES_URL文件“/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py”,第154行,在urlopen中返回opener.open(url,data,timeout )文件“/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py”,第435行,打开响应= meth(req,response)在http_response'htt'中输入文件“/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py”,第548行,请求,响应,代码,msg,hdrs)文件“/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py”,第473行,错误返回self._call_chain (* args)文件“/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py”,第407行,在_call_chain result = func(* args)文件“/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py”,第556行,http_error_default引发HTTPError(req.get_full_url( ),代码,消息,h drs,fp)urllib2.HTTPError:HTTP错误400:错误请求