首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有没有免费的API来检索标准普尔500指数的成分股符号?

问有没有免费的API来检索标准普尔500指数的成分股符号?
EN

Stack Overflow用户
提问于 2012-12-08 02:56:11
回答 3查看 16.1K关注 0票数 6

某种免费的REST API将是理想的,但一般来说,是否有任何免费的API或web服务或CSV文件(不在密码提示符后)或任何东西可以查询,以获得标准普尔500指数成分股的最新列表?

我已经通过雅虎财经的应用程序接口( API )和Markit on demand (http://dev.markitondemand.com/)查看了标准普尔的网站(http://www.standardandpoors.com),但目前还没有找到任何东西。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-12-08 03:10:08

我找到了http://finviz.com/export.ashx?v=152&f=idx_sp500&ft=1&ta=1&p=d&r=1&c=1

:-)

但是我还没有找到Finviz API文档。

:-(

彭博社似乎有一部open api。如果你到处找,也许能找到你需要的数据。

票数 1
EN

Stack Overflow用户

发布于 2013-06-09 02:52:11

也有类似的需求。您可以使用Wikipedia API或parse html来获取S&P500 http://en.wikipedia.org/wiki/List_of_S%26P_500_companies中的符号列表

您现在可以通过以下方式安装和使用模块

代码语言:javascript
复制
pip install finsymbols

我目前通过维基百科获取符号列表。它不是rest,但可以很容易地转换为rest API。它是用python编写的。

代码语言:javascript
复制
>>import sys
>>sys.path.append('/home/skillachie/Desktop/')
>>import finsymbols

sp500 = finsymbols.get_sp500_symbols()

pprint.pprint(sp500)

{'company': u'Xcel Energy Inc',
  'headquaters': u'Minneapolis, Minnesota',
  'industry': u'Multi-Utilities & Unregulated Power',
  'sector': u'Utilities',
  'symbol': u'XEL'},
 {'company': u'Xerox Corp.',
  'headquaters': u'Norwalk, Connecticut',
  'industry': u'IT Consulting & Services',
  'sector': u'Information Technology',
  'symbol': u'XRX'},
 {'company': u'Xilinx Inc',
  'headquaters': u'San Jose, California',
  'industry': u'Semiconductors',
  'sector': u'Information Technology',
  'symbol': u'XLNX'},
 {'company': u'XL Capital',
  'headquaters': u'Hamilton, Bermuda',
  'industry': u'Property & Casualty Insurance',
  'sector': u'Financials',
  'symbol': u'XL'},

如果你感兴趣,可以在这里获取更多信息http://skillachie.github.io/finsymbols/

票数 7
EN

Stack Overflow用户

发布于 2014-11-26 06:35:15

使用python,您可以尝试我刚刚编写的这段代码(有点难看,但还不错)。(它实际上返回502个报价器。这是正确的)

代码语言:javascript
复制
 from urllib import request
    from bs4 import BeautifulSoup
    import datetime
    import dateutil.relativedelta as dr
    import pandas as pd


    def get_constituents():
        # URL request, URL opener, read content
        req = request.Request('http://en.wikipedia.org/wiki/List_of_S%26P_500_companies')
        opener = request.urlopen(req)
        content = opener.read().decode() # Convert bytes to UTF-8

        soup = BeautifulSoup(content)
        tables = soup.find_all('table') # HTML table we actually need is tables[0] 

        external_class = tables[0].findAll('a', {'class':'external text'})

        tickers = []

        for ext in external_class:
            if not 'reports' in ext:
                tickers.append(ext.string)

        return tickers
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13769278

复制
相关文章

相似问题

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