utils.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:DQN 作者: jjakimoto 项目源码 文件源码
def get_sap_symbols(name='sap500'):
    """Get ticker symbols constituting S&P

    Args:
        name(str): should be 'sap500' or 'sap100'
    """
    if name == 'sap500':
        site = 'http://en.wikipedia.org/wiki/List_of_S%26P_500_companies'
    elif name == 'sap100':
        site = 'https://en.wikipedia.org/wiki/S%26P_100'
    else:
        raise NameError('invalid input: name should be "sap500" or "sap100"')
    # fetch data from yahoo finance
    page = urlopen(site)
    soup = BeautifulSoup(page, 'html.parser')
    table = soup.find('table', {'class': 'wikitable sortable'})
    symbols = []
    for row in table.findAll('tr'):
        col = row.findAll('td')
        if len(col) > 0:
            symbol = col[0].string.replace('.', '-')
            symbols.append(str(symbol))
    return symbols
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号