Python pandas Google 为国际股票融资——寻找通过 Google 获取国际股票价格历史的方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22779850/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 21:52:57  来源:igfitidea点击:

Python pandas Google finance international stocks - looking for way to get international stocks price history with Google

pythonpandas

提问by jason

This works: domestic stocks

这个作品:国内股票

gticker='NYSE:IBM'
import pandas.io.data as web
dfg = web.DataReader(gticker, 'google', '2013/1/1', '2014/3/1')

This does not: international stocks

这不:国际股票

gticker='HKG:0700'
import pandas.io.data as web
dfg = web.DataReader(gticker, 'google', '2013/1/1', '2014/3/1')

even though for both, you can go to the "Historical prices" link and see historical data.

即使对于两者,您也可以转到“历史价格”链接并查看历史数据。

Any suggestions?

有什么建议?

采纳答案by Karl D.

The DataReader for google wants to download a csv file. So for 'goog' it requests the following URL which fetches the csv file:

google 的 DataReader 想要下载一个 csv 文件。因此,对于“goog”,它请求获取 csv 文件的以下 URL:

http://www.google.com/finance/historical?q=GOOG&startdate=Jan+1%2C+2013&enddate=Mar+1%2C+2014&output=csv

http://www.google.com/finance/historical?q=GOOG&startdate=Jan+1%2C+2013&enddate=Mar+1%2C+2014&output=csv

This is true for all the domestic stocks (like IBM). But for 'HKG:0700' it requests:

所有国内股票(如IBM)都是如此。但是对于 'HKG:0700' 它要求:

http://www.google.com/finance/historical?q=HKG%3A0700&startdate=Jan+01%2C+2014&enddate=Mar+01%2C+2014&output=csv

http://www.google.com/finance/historical?q=HKG%3A0700&startdate=Jan+01%2C+2014&enddate=Mar+01%2C+2014&output=csv

and that produces a 'The requested URL was not found on this server.' error. You can look at the historical data at:

这会产生“在此服务器上找不到请求的 URL”。错误。您可以在以下位置查看历史数据:

http://www.google.com/finance/historical?q=HKG%3A0700&startdate=Jan+01%2C+2014&enddate=Mar+01%2C+2014

http://www.google.com/finance/historical?q=HKG%3A0700&startdate=Jan+01%2C+2014&enddate=Mar+01%2C+2014

But it doesn't look like you can get a csv file.

但看起来您无法获得 csv 文件。

You see what it is doing pandas/io/data.py when it creates the URL:

当它创建 URL 时,你会看到它在做什么 pandas/io/data.py:

# www.google.com/finance/historical?q=GOOG&startdate=Jun+9%2C+2011&enddate=Jun+8%2C+2013&output=csv
url = "%s%s" % (_HISTORICAL_GOOGLE_URL,
                urlencode({"q": sym,
                           "startdate": start.strftime('%b %d, ' '%Y'),
                           "enddate": end.strftime('%b %d, %Y'),
                           "output": "csv"}))

回答by ricca

It seems Google Finance only support CSV download for US and UK market, as the link "Download to spreadsheet" under "Historical chart" only appears for stocks listed in these two markets in the following example:

Google 财经似乎只支持美国和英国市场的 CSV 下载,因为“历史图表”下的“下载到电子表格”链接仅在以下示例中出现在这两个市场中列出的股票:

HSBC stock listed in UK https://www.google.com/finance/historical?q=LON%3AHSBA

汇丰股票在英国上市 https://www.google.com/finance/historical?q=LON%3AHSBA

HSBC stock listed in US https://www.google.com/finance/historical?q=NYSE%3AHSEA

汇丰股票在美国上市 https://www.google.com/finance/historical?q=NYSE%3AHSEA

HSBC stock listed in Hong Kong https://www.google.com/finance/historical?q=HKG%3A0005

香港上市汇丰股票 https://www.google.com/finance/historical?q=HKG%3A0005